Is it possible to do something like this:
start=1 end=10 echo {$start..$end} # Ouput: {1..10} # Expected: 1 2 3 ... 10 (echo {1..10})
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Example. Command substitution is generally used to assign the output of a command to a variable. Each of the following examples demonstrates the command substitution − #!/bin/sh DATE=`date` echo "Date is $DATE" USERS=`who | wc -l` echo "Logged in user are $USERS" UP=`date ; uptime` echo "Uptime is $UP"
In bash, brace expansion happens before variable expansion, so this is not directly possible.
Instead, use an arithmetic for
loop:
start=1 end=10 for ((i=start; i<=end; i++)) do echo "i: $i" done
i: 1 i: 2 i: 3 i: 4 i: 5 i: 6 i: 7 i: 8 i: 9 i: 10
You should consider using seq(1)
. You can also use eval:
eval echo {$start..$end}
And here is seq
seq -s' ' $start $end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With