# Multiple platform scripts

**URL:** <https://community.unix.com/t/multiple-platform-scripts/169728>\
**Category:** Shell Programming and Scripting\
**Created:** [March 13, 2007, 3:41am UTC](https://community.unix.com/t/multiple-platform-scripts/169728 "2007-03-13T03:41:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_ptr](https://community.unix.com/user_avatar/community.unix.com/_ptr/32/519_2.png) [@\_ptr](https://community.unix.com/u/_ptr)\
**Post date:** [March 13, 2007, 3:41am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/1 "2007-03-13T03:41:57Z")

</div>

Hello  
I'm writing a script system in bash that I want to run on Un\*x (SunOS), Linux, and cygwin also.  
The scripts starts with the sha-bang #!/bin/bash, but I experienced that the bash interpreter path are different on these platforms.

My question is how can I manipulate the command interpreter line on my scripts  
to run on each platform.  
(I think to made a setup script to replace the first line in all of my scripts depending on the platform on which I'm running the scripts)  
I also tried the:  
#!/bin/bash  
#!/usr/bin/local/bash  
but if the command interpreter path are not correct in the first line, the OS does not looks for the command interpreter in the second line.

Many thanks beforehand

---

<div class="post-metadata">

**Author:** ![ghostdog74](https://community.unix.com/letter_avatar/ghostdog74/32/6_449c533f586939b6e5f246632a46421f.png) [@ghostdog74](https://community.unix.com/u/ghostdog74)\
**Post date:** [March 13, 2007, 4:07am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/2 "2007-03-13T04:07:37Z")

</div>

There may be other ways, but i find it easiest to just do this:

```nohighlight
# bash yourscript.sh

```

This should take care of the shebang problem.

---

<div class="post-metadata">

**Author:** ![\_ptr](https://community.unix.com/user_avatar/community.unix.com/_ptr/32/519_2.png) [@\_ptr](https://community.unix.com/u/_ptr)\
**Post date:** [March 13, 2007, 4:13am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/3 "2007-03-13T04:13:54Z")

</div>

yes I know, but I want to launch my scripts in a normal form:  
script\_name.sh params.  
Anyway, thanks.

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [March 13, 2007, 7:14pm UTC](https://community.unix.com/t/multiple-platform-scripts/169728/4 "2007-03-13T19:14:20Z")

</div>

> [@\*ptr](#):
>
> My question is how can I manipulate the command interpreter line on my scripts  
> to run on each platform.

#!/usr/bin/env bash

---

<div class="post-metadata">

**Author:** ![\_ptr](https://community.unix.com/user_avatar/community.unix.com/_ptr/32/519_2.png) [@\_ptr](https://community.unix.com/u/_ptr)\
**Post date:** [March 14, 2007, 2:27am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/5 "2007-03-14T02:27:53Z")

</div>

> [@cfajohnson](#):
>
> #!/usr/bin/env bash

Yes, you're right thx. It works fine on Linux  
But on SunOS the /usr/bin/env bash opens a new subshell, and my script doesn't start  
running until I logout from the new shell. (actually no additional terminal is opened, just a shell started in the current terminal)  
The newly started shell remains active until I press Ctrl+D one or more times to logout (on several scripts I observed that I need to press ^D three times to logout from the shell), after that the script starts running.

I'm wondering why exactly acts on SunOS in this way....

Anyway, thanks a lot for the suggestion Mr. Johnson

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [March 14, 2007, 3:05am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/6 "2007-03-14T03:05:49Z")

</div>

What version of Solaris are you using? cfajohnson's suggestion seems to work ok on Sol10.

---

<div class="post-metadata">

**Author:** ![\_ptr](https://community.unix.com/user_avatar/community.unix.com/_ptr/32/519_2.png) [@\_ptr](https://community.unix.com/u/_ptr)\
**Post date:** [March 14, 2007, 3:18am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/7 "2007-03-14T03:18:46Z")

</div>

SunOS 5.8 on Sparc SunBlade server

---

<div class="post-metadata">

**Author:** ![ghostdog74](https://community.unix.com/letter_avatar/ghostdog74/32/6_449c533f586939b6e5f246632a46421f.png) [@ghostdog74](https://community.unix.com/u/ghostdog74)\
**Post date:** [March 14, 2007, 3:49am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/8 "2007-03-14T03:49:54Z")

</div>

env looks up bash in the list of directories specified by the  
$PATH environment variable.  
On few systems env might not even be in /usr/bin (although its rare). bash might not also be in $PATH variable.

```nohighlight
 bash /path/to/script 

```

is still better in terms of portability , just what i think.

---

<div class="post-metadata">

**Author:** ![\_ptr](https://community.unix.com/user_avatar/community.unix.com/_ptr/32/519_2.png) [@\_ptr](https://community.unix.com/u/_ptr)\
**Post date:** [March 14, 2007, 3:52am UTC](https://community.unix.com/t/multiple-platform-scripts/169728/9 "2007-03-14T03:52:22Z")

</div>

you are right. Probably I will make a wrapper on the top of the entire script system, and I will call the scripts from the wrapper in this way.  
Many thanks to everybody.
