Find the answer to your Linux question:
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 ...
  1. #1
    Linux 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

    #!/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
    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.

    Any workaround on this?

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Exclamation

    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
    -------------------

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    65
    sorry i couldn't understand ur post from the beginning
    Code:
    args=("$@")
    for((i=2;$i<=$#;i++))
     do
            echo ${args[$i]}
     done
    this code if u don't want to make shift

  4. #4
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    For parameters beyond $9 enclosed the parameter no. in '{}'s

    Parameter 10 - ${10}
    .
    .
    Parameter 12 - ${12}

  5. #5
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    506
    Let me chime in too!
    Code:
    #!/bin/bash
    echo $1 > test1.txt
    shift
    echo $* > test2.txt
    (I didn't test it, but I'm pretty sure it's right.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...