A
A
Arkadiy Mishin2015-04-30 11:45:19
linux
Arkadiy Mishin, 2015-04-30 11:45:19

How to make bash process more than 9 variables?

I have a problem, I can’t understand how to solve
in the first option, all variables are processed normally
[email protected]:/etc/cron_user# ./test.sh y1 y2.ru y3.ru y4.ru y5.ru y6.ru y7.ru y8. ru y9.ru y10.ru
y1 y2.ru y3.ru y4.ru y5.ru y6.ru y7.ru y8.ru y9.ru y10
in the second $1 is confused with $10 because of the dot in the value and is treated as $1+ "0"
[email protected]:/etc/cron_user# ./test.sh y1.ru y2.ru y3.ru y4.ru y5.ru y6.ru y7.ru y8.ru y9.ru y10.ru
y1.ru y2.ru y3.ru y4.ru y5.ru y6.ru y7.ru y8.ru y9.ru y1.ru0
simple code
[email protected]:/etc/cron_user# cat test.sh
#!/bin/bash
echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10
[email protected]:/etc/cron_user#

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
egor_nullptr, 2015-04-30
@Arkasha18

echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10}

S
Stanislav, 2015-04-30
@mastan

You can use shift, works with any number of arguments:

#!/bin/bash

while (( "$#" )); do
echo -n "$1 "
shift
done
echo

V
Vlad Zhivotnev, 2015-04-30
@inkvizitor68sl

Always take variables in ${ } - this saves a lot of these errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question