I have a script with the following variable assignment:
TEST_VARIABLE=${3#?} What does the ${3#?} do?
That is called parameter expansion:
$3 is your variable, which is the third parameter of the script/function.# will remove the shortest prefix of the variable.? is the pattern you are looking for (in this case is any character).So basically you remove the shortest prefix of the variable named 3 until you find the pattern.
In general, we can consider:
${variable_name[option][pattern]} There are other options like:
## remove largest prefix.% remove shortest suffix.%% remove largest suffix.Which you can combine with other patterns, for example, for getting the last field of a CSV line:
> string="asdf,1234,aa,foo22" > echo ${string##*,} foo22 Notice how we have removed the largest prefix searching for the pattern "any character(s) followed by a comma".
> set -- 1 2 foo > echo "$3" foo TEST_VARIABLE=${3#?} > echo "$TEST_VARIABLE" oo It assigns the value of the third positional parameter without its first char to the variable TEST_VARIABLE (the positional parameter itself is not changed); used in functions or shell scripts:
./myscript 1 2 foo # or myfunc 1 2 foo # within each $3 is foo In order to have positional parameters within an interactive shell you need set.
-dash? Still, it's impossible to judge without the code. By the way, though, it doesn't actually drop the first character of the positional parameter - it expands without it. So set -- one two three ; echo "${3#?}" "$3" gets you hree and three. You don't lose anything - it's still there. You'd have to set -- to clear the args.