Results 1 to 6 of 6
Hey is it common to use
Code:
#!/bin/bash -i
And what is the correct method to run a .sh file?
Code:
$ bash
$ .
$ ./...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-04-2013 #1Just Joined!
- Join Date
- Mar 2013
- Posts
- 2
BASH run & -i
Hey is it common to use
And what is the correct method to run a .sh file?Code:#!/bin/bash -i
Code:$ bash $ . $ ./
Last edited by vocal300; 03-04-2013 at 11:35 PM. Reason: adjust code
- 03-05-2013 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 398
For a script to run there are three things that need to be done.
1) In the script itself it must start with a special comment (referred to as the she-bang line or hack). This is a comment line in the script as the first line:
This tells the program that reads and runs the script (in this case bash which is found in "/bin/bash").Code:#!/bin/bash
2) The permissions need to be changed to allow it to be executed. Here some examples of changing the permissions of a file:
3) Place the file in a directory that you have added to your PATH environment variable or include the path when executing the script (or program binary if using C, C++, FORTRAN, ADA, etc).Code:chmod 755 filename chmod u+x filename
- 03-05-2013 #3
Addendum:
1) Consider using
Not all unixes have bash in /bin/ , but all have /usr/bin/env.Code:#!/usr/bin/env bash
3) Should you place your script in the system $PATHs, then my advise is to do it controlled. Aka by wrapping your script in a rpm/deb package.You must always face the curtain with a bow.
- 03-05-2013 #4Just Joined!
- Join Date
- Mar 2013
- Posts
- 2
Ok
Back to my question.
I have a script. It works fine with either #!/usr/bin/env bash or #!/bin/bash. But I have another script using the history command, Yes I read it's disabled. But when I run it as . scriptfile.sh or source scriptfile.sh it works 100%. Why?
And why all the different ways to run scripts? Say I want to share with Mary, Paul & Tara. I don't want them to request changing environment variables to make this work.
- 03-06-2013 #5Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 398
This method should never be used for admin scripts that might be used during the boot process as "/usr" may not be mounted. Yes I know udev is breaking this but that does not make it correct. That is why login shells suxh as bash are in "/bin/".
- 03-06-2013 #6Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 398


Reply With Quote

