Search code examples
bashscriptingsunos

How to change shell in script temporary in sunOS?


The machine has default shell "sh" and running SunOS. I try to run the script like:

#!/bin/bash
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9
echo $NLS_LANG

I get the output:

NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9^M: is not an identifier

I think the script cannot execute this command but do not understand why. Maybe It is because the default shell is not bash shell.

Could you help me to convert sh shell into bash shell inside of the script.

P.S: I have also tried with #!/bin/sh but result is the same


Solution

  • Are you sure that Bash is where you say it is? Consider using the following shebang:

    bash-3.2$ cat ./test.sh
    #!/usr/bin/env bash
    export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9
    echo $NLS_LANG
    

    Ensure your shell script is executable:

    bash-3.2$ chmod +x ./test.sh
    bash-3.2$ ls -l ./test.sh
    -rwxr-xr-x  1 paj  staff  81 26 Apr 11:52 ./test.sh
    

    And run...

    bash-3.2$ ./test.sh
    AMERICAN_AMERICA.WE8ISO8859P9