Usage of #!/bin/sh vs #!/bin/bash shell scripts?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Usage of #!/bin/sh vs #!/bin/bash shell scripts?
# 1  
Old 10-09-2016
Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts:
1.) Are the commands of the base shell scripts a subset of bash commands?

2.) Assume I got a long, long script WITHOUT the first line.
How can I find out if the script was originally designed für "sh" or "bash"?

3.) How can I check a given script for syntax (not: logical) errors?

4.) Currently I have to enter

./myscript

to execute a certain script

How can I setup Linux so that the leading ".7" is not necessary any more?

Peter
# 2  
Old 10-09-2016
1) It is other way around. ie bash is a superset of sh.

2) without shebang line, i guess have to go through the scirpts , IMHO.

3) bash -n option can be helpful here with its own limitations.
Code:
bash -n <file>

check bash man page.

4)
Quote:
How can I setup Linux so that the leading ".7" is not necessary any more?
Could you explain a bit here ?
# 3  
Old 10-09-2016
Certainly a typo, Peter means ./
Answer:
You can put the . in your PATH, and define it in the login files; e.g. in .profile have
Code:
export PATH=/bin:/usr/bin:/usr/sbin:/sbin:.

For safety reasons the . should be after the standard pathes, so an "ls" will run /bin/ls or /usr/bin/ls, not a ./ls
BTW the answer for 1) is a plain yes.
# 4  
Old 10-09-2016
You might consider creating your own dedicated directory for the script in question (and those that will follow Smilie. Put that directory in your path, not the ".".

Juha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. AIX

Redistribution bin required for AIX. j7r164redist.7.1.0.25.bin

Hi, I am planning to install a version of Informatica on my AIX box. It requires a specific java build in pap6470_27sr2-20141101_01(SR2). The current link for IBM 64-bit SDK for AIX®, JavaTM Technology Edition, Version 7 Release 1 has a more recent version in j7r164redist.7.1.0.75.bin. Is... (4 Replies)
Discussion started by: meetpraveens
4 Replies

3. UNIX for Dummies Questions & Answers

Usage of #!/bin/ksh

Hi, In the beginning of Shell script, we give a statement like #!/bin/ksh I have 2 questions related to this, 1) It could denote about the shell we want to use, what is the real usage of this? My shell script works even without this statement, is it a mandatory one. 2) I'm using... (7 Replies)
Discussion started by: Dev_Dev
7 Replies

4. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

5. Shell Programming and Scripting

Error in shell script when #!/bin/bash is used as shebang

#!/bin/ksh echo -en "\033|||'-')) echo -e "\033 The above script works fine when the interpreter is ksh, but outputs the following error when #!/bin/bash is used as shebang: test.sh: line 5: syntax error near unexpected token `(' test.sh: line 5: `case "$ACTIVATION_KEY" in +(|||'-'))' (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. Shell Programming and Scripting

#!/bin/bash and #1bin/sh command not found error on mac osx terminal/shell script

i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine. then last week i wrote capture.sh and it... (2 Replies)
Discussion started by: danpaluska
2 Replies

7. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

8. Shell Programming and Scripting

Why does my /bin/csh take longer than /bin/perl?

Okay, so I have two "Hello, world!" scripts, "test.pl" and "test.sh". #!/bin/perl -w use strict; print "Hello, world!\n"; #!/bin/csh echo Hello,\ world! When I run test.pl, it runs instantly, always. When I run test.sh, it takes anywhere between 4 and 22 seconds! I'd like to know what... (3 Replies)
Discussion started by: acheong87
3 Replies

9. Shell Programming and Scripting

Using #! /bin/sh in Shell scripts

Hi All, What does #! /bin/sh mean in a shell script? Is it mandatory to include in a shell script? I'm able to execute the shell script without it. Any help on this would be appreciated. (4 Replies)
Discussion started by: sumesh.abraham
4 Replies

10. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question