Results 1 to 5 of 5
Can bash script do this
./script.sh test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12
#!/bin/bash
case $1 in
*)
echo $1 > /root/test1.txt
echo $2 $3 ...
- 11-25-2009 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
bash script more than $9 possible?
Can bash script do this
./script.sh test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12
However, it could only output up to $9. I want to dump $1 to a file and the rest variables to a single file. I notice that it could only dump up to $9. The variable $2-19 is a sentence and I cannot put a quote just to make a sentence be a single variable.#!/bin/bash
case $1 in
*)
echo $1 > /root/test1.txt
echo $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 > /root/test2.txt
;;
esac
Any workaround on this?
- 11-25-2009 #2
shift command seems like perfect candidate for you. check this url Shift - reposition command line parameters
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 11-25-2009 #3Just Joined!
- Join Date
- Aug 2005
- Posts
- 65
sorry i couldn't understand ur post from the beginning
this code if u don't want to make shiftCode:args=("$@") for((i=2;$i<=$#;i++)) do echo ${args[$i]} done
- 11-25-2009 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
For parameters beyond $9 enclosed the parameter no. in '{}'s
Parameter 10 - ${10}
.
.
Parameter 12 - ${12}
- 11-26-2009 #5
Let me chime in too!
(I didn't test it, but I'm pretty sure it's right.)Code:#!/bin/bash echo $1 > test1.txt shift echo $* > test2.txt


Reply With Quote