parameter-expansion Questions

3

Solved

I try to substract the first string before a dot (.) in bash. For instance: 1.2.3 -> 1 11.4.1 -> 11 I used the following command based on the docs: s=4.5.0 echo "${s%.*}" But it oupt...
Monomania asked 22/11, 2016 at 9:40

2

Solved

I'm trying to port some code from bash 5.1 to 4.2.46. One function which tries to strip color codes from a specifically formatted string stopped working. This is a sample string text in such format...
Broch asked 5/1, 2022 at 0:44

3

Solved

I got the following variable: set location "America/New_York" and want to display only the part before the / (slash) using fish shell syntax. Expected result America Bash equivalent Using...
Lumumba asked 9/12, 2015 at 20:16

5

Solved

I am having trouble remembering which one of the parameter expansions ${var%subst} or ${var#subst} remove from the front and which one from the back of the string. Example: $ var=/a/b/c $ ech...
Countertenor asked 1/3, 2021 at 11:39

2

Solved

Say I read some data into a Bash array: $ IFS=" " read -a arr <<< "hello/how are/you iam/fine/yeah" Now, I want to print the first /-sliced field for each element in the array. What I ...
Waiwaif asked 8/6, 2016 at 9:11

2

Solved

I am after a pure bash solution to "slugify" a variable and that is not as ugly as mine. slugify: lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with -. No ...
Gramps asked 1/11, 2017 at 8:6

3

Solved

For debugging my scripts, I would like to add the internal variables $FUNCNAME and $LINENO at the beginning of each of my outputs, so I know what function and line number the output occurs on. foo...

2

Solved

In the following block of code, how are line# 3 and 4 evaluated? for f in "${CT_LIB_DIR}/scripts/build/debug/"*.sh; do _f="$(basename "${f}" .sh)" _f="${_f#???-}" __f="CT_DEBUG_${_f^^}" done ...
Euridice asked 11/7, 2019 at 23:24

4

Solved

What is the correct way to call some command stored in variable? Are there any differences between 1 and 2? #!/bin/sh cmd="ls -la $APPROOTDIR | grep exception" #1 $cmd #2 eval "$cm...
Electric asked 12/1, 2011 at 12:13

2

Solved

I recently came across this really neat syntax, in the context of creating bash functions which can accept an argument or a stream from STDIN (i.e. can be piped to). On the surface, I understand wh...
Save asked 30/1, 2019 at 9:30

2

Solved

I am trying to append a path to the end of my PERL5LIB environment variable, but I am not sure that this variable will always exist. If it doesn't exist I would like to simply initialize it to the ...
Catholicism asked 8/12, 2017 at 21:55

2

Solved

Is there any way to use !$ in a parameter expansion context? The desired usage that motivates this question is rapid (in terms of key strokes) alteration of the name of a file (e.g., instead of sav...
Coastline asked 11/6, 2017 at 0:55

1

Solved

Problem The behaviour of !(pattern-list) does not work the way I would expect when used in parameter expansion, specifically ${parameter/pattern/string} Input a="1 2 3 4 5 6 7 8 9 10" ...
Captious asked 29/5, 2017 at 12:3

2

I've googled and tried so many things and never could get anything to work with ${parameter@operator}. All I find is more links to the same documentation. So I think a proper answer with practical ...
Warranty asked 22/11, 2016 at 1:6

2

Solved

I'm trying to do a simple regex statement in a bash script that will match and substitute the end of a word. Below is what I'm trying to do. wordh > word:’ Below is the code I'm using. #!/bi...
Energetic asked 9/1, 2016 at 6:24

2

Inside of a while read line loop, I see this variable expansion ${line/device name:}. I've tried running the script with my own input file and it just prints out the line. Can you tell me what th...
Thirsty asked 16/9, 2015 at 22:19
1

© 2022 - 2024 — McMap. All rights reserved.