How do I run a shell script without using “sh” or “bash” commands?

Add a "shebang" at the top of your file: #! /bin/bash And make your file executable (chmod +x script. Sh).

Finally, modify your path to add the directory where your script is located: export PATH=$PATH:/appropriate/directory (typically, you want $HOME/bin for storing your own scripts).

I tried that out. Now I can run it without the "sh" command. But I still have to prefix the command with ".

/" which I don't want to. :) – Rameez Hussain Jan 8 at 18:26 See comments about the path. You need to put your script in a directory which you have to append to your PATH.

– fge Jan 8 at 18:33.

Just make sure it is executable, using chmod +x. By default, the current directory is not on your PATH, so you will need to execute it as . /script.Sh - or otherwise reference it by a qualified path.

Alternatively, if you truly need just script. Sh, you would need to add it to your PATH.(You may not have access to modify the system path, but you can almost certainly modify the PATH of your own current environment. ) This also assumes that your script starts with something like #!

/bin/sh. You could also still use an alias, which is not really related to shell scripting but just the shell, and is simple as: alias script. Sh='sh script.

Sh' Which would allow you to use just simply script.Sh (literally - this won't work for any other *. Sh file) instead of sh script.sh.

Thanks for your reply. I tried using aliases earlier. But nothing happened.

I placed it immediately after the "#! /usr/local/bin/bash" line. What do you think is wrong?

– Rameez Hussain Jan 8 at 18:28 An alias can't be defined within your script - it has to be declared as part of your current environment. So just run the alias command at the shell prompt, and then the alias will be available to run the command with. – ziesemer Jan 8 at 18:39.

You have to enable the executable bit for the program. Chmod +x script. Sh Then you can use .

/script. Sh You can add the folder to the PATH in your . Bashrc file (located in your home directory).

Add this line to the end of the file: export PATH=$PATH:/your/folder/here.

I forgot to mention that I have already set the right permissions. I used the command "chmod 755 script. Sh" – Rameez Hussain Jan 8 at 18:29.

These are some of the pre-requisites of using directly the script name: Add the sha-bang {#! /bin/bash) line at the very top. Using chmod u+x scriptname make the script executable.

Place the script under /usr/local/bin folder. Run the script using just the name of the script. Note: The reason I suggested to place it under /usr/local/bin folder is because most likely that will be path already added to your PATH variable.

Update: If you don't have access to the /usr/local/bin folder then do the following: Create a folder in your home directory and let's call it myscripts. Do ls -lart on your home directory, to identify the start-up script your shell is using. It should either be .

Profile or .bashrc. Once you have identified the start up script, add the following line in your script - export set PATH=$PATH:~/myscript. Once added, source your start-up script or log out and log back in.

Execute your script using script name.

I tried doing this but I don't have the permissions to access the /usr/local/bin folder. I am using a university computer. – Rameez Hussain Jan 8 at 18:37 Added updates to the answer.

– Jaypal Singh Jan 8 at 18:42 Could you please tell me what you mean by "source your start-up script"? – Rameez Hussain Jan 8 at 18:58 Sourcing the start-up script means to execute it so the newly set parameter to PATH variable is picked up by shell. This can be done by doing ..bashrc.

That is, just put . Followed by space and then your start-up script name. – Jaypal Singh Jan 8 at 18:59 I don't know what the problem with the system is.

I created a new shell script named "hello" with just an "echo "hello" " in it. I changed its permissions and tried . /hello.

It dosn't work. It says- – Rameez Hussain Jan 8 at 19:42.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions