Find the answer to your Linux question:
Results 1 to 2 of 2
I am pretty new to BASH scripting, I have a script that will build a list of hosts and it works fine Code: for ((i=$START; i<=$END; i++)); do echo "$NAME$i"; ...
  1. #1
    Just Joined! lockon's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    25

    Question [SOLVED] BASH Script help

    I am pretty new to BASH scripting, I have a script that will build a list of hosts and it works fine
    Code:
    for ((i=$START; i<=$END; i++)); do echo "$NAME$i"; done
    But I need it to build the START and END on different number formats (i.e. 1 -> 10, 01->10, 001 ->010)

    I am trying to use the seq command but can't get it to work quite right with the -w flag in the following
    Code:
    for ((myseq=$START; myseq<=$END; myseq ++))
    do
    echo "$NAME${myseq}"
    done
    I am fully aware that this syntax is probably wrong, and need to know how to correct it.

    If you need more info I can provide it.
    Thanks

  2. #2
    Just Joined! lockon's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    25
    Got it
    Code:
    echo What is the host name minus the numbering?
    read NAME
    echo What are the starting and ending numbers for the $NAME hosts?
    read START END
    echo " "
    echo $NAME$START
    echo "Through"
    echo $NAME$END
    echo " "
    
    for a in `seq -w $START $END`
    do
    echo $NAME$a
    done

Posting Permissions

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