VMware vSphere

 View Only
  • 1.  run bash script

    Posted Jan 17, 2019 08:09 AM

    In ESXi 6.0 host I created Bash script which I renamed as "test.sh" and I'm not able to run it if I type:

    ./test.sh

    While I type It's ok:

    sh test.sh

    Is there way to run script as ./test.sh ?!



  • 2.  RE: run bash script

    Posted Jan 17, 2019 10:27 AM

    Ricky73,

    Keep in mind that the shell of ESXi is not a traditional linux shell, it's a busybox shell.  There is no concept of bash, but you still have basic shell (sh) functionality.

    ls -l /bin/sh

    lrwxrwxrwx    1 root     root            35 Nov  4 23:26 /bin/sh -> /usr/lib/vmware/busybox/bin/busybox

    It is also possible to create and run a script, but you need to specify what shell to be used in the script similar to this:

    [root@esx-01:~] cat test.sh

    #!/bin/sh

    echo test

    [root@esx-01:~] chmod +x test.sh

    [root@esx-01:~] ./test.sh

    test

    Good luck!

    Lars



  • 3.  RE: run bash script

    Posted Jan 17, 2019 11:45 AM

    I thank you but my file test.sh contents already:

    #!/bin/bash

    echo test

    file permissions are 777

    but nothing!

    I don't see no bash file in ESXi host, I lookuped "bash" into server but no results.



  • 4.  RE: run bash script
    Best Answer

    Posted Jan 17, 2019 01:16 PM

    There is no bash on ESXi, only sh (but not a real sh, just busybox).

    So you need to change your line

    #!/bin/bash

    to

    #!/bin/sh

    in order for your script to work.

    Lars



  • 5.  RE: run bash script

    Posted Mar 16, 2021 01:04 AM

    Hi 

    Thanks for the great answer.

    I want to declare a map in a my shell script on esx.

    I tried 

    declare -A MAP=( [key1]=val1 [key2]=val2 )  like in linux .
    This does not work. I get many errors including declare not found, MAP not found etc.
     
    So how do I declare a key value pair in esx shel script
     
    Thanks
    -Dee


  • 6.  RE: run bash script

    Broadcom Employee
    Posted Mar 17, 2021 10:18 AM

    "declare" isn't supported / provided by the busybox shell