Results 1 to 7 of 7

Thread: shell script

  1. #1
    Join Date
    Jul 2007
    Beans
    25

    shell script

    Hi there.
    For loop in Ubuntu works fine directly from the command line. But it doesn't when placed in the shell script.
    Any ideas anyone ?


    user@server:~/wtest# for i in {1..10};do echo "$i";done
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    cat script.sh
    #!/bin/bash
    for i in {1..10};do echo "$i";done

    user@server:~/wtest# sh script.sh
    {1..10}

  2. #2
    Join Date
    Nov 2008
    Location
    Sheffield, UK
    Beans
    1,514
    Distro
    Ubuntu

    Re: shell script

    try
    ./script

    not

    sh script

  3. #3
    Join Date
    Nov 2010
    Location
    India
    Beans
    Hidden!

    Re: shell script

    Quote Originally Posted by SlugSlug View Post
    try
    ./script

    not

    sh script
    +1 and sh you have to use if your running your script from Other file systems like NTFS FAT etc
    Dont miss anything even it is small. one small pin is enough to bring down a man.


  4. #4
    Join Date
    Jul 2007
    Beans
    25

    Re: shell script

    Thanks.
    I have figured it out already. But I am sure scripts were working in the old days when preceded with "sh".
    Looks to me like another werid change in the system.
    Warmest regards,
    Peter

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: shell script

    the deal is that bash and dash (sh) have a different set of features and not everything is going to work if you try sh bash_script.sh. Just use #! line to define shell and run the script without calling shell explicitly.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #6
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,306
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: shell script

    Quote Originally Posted by nagileon View Post
    Thanks.
    I have figured it out already. But I am sure scripts were working in the old days when preceded with "sh".
    Looks to me like another werid change in the system.
    A sh script can be executed by
    Code:
    sh scriptname
    but for a bash script you would need
    Code:
    bash scriptname
    Nothing has changed here. Your original result was obtained by sh interpreting the script according to its own syntax and semantics, but you want it to be interpreted by bash.

    Note that the shebang (line 1 of your script) is only effective when invoking the program directly by name (e.g. ./scriptname ). It has no effect if you put the name of the interpreter at the start of the command.

  7. #7
    Join Date
    Jul 2007
    Beans
    25

    Re: shell script

    One more question:

    How do I get rid of the colorization info from a variable:

    rvc user@server --cmd "vm.on /server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/$thevm" --cmd "exit"

    no matches for "/server/dev/computers/mycluster/resourcePool/pools/PoolX/vms/XYZ.pool.local-PoolX\e[0m"

    I should get: XYZ.pool.local-PoolX

    But the clorization infor is attached to the variable for some strange reason.

Bookmarks

Posting Permissions

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