1.2 KiB
1.2 KiB
title
title |
---|
Shell scripting |
Shell scripting
In the command line, a shell script is an executable file that contains a set of instructions that the shell will execute. Its main purpose is to reduce a set of instructions (or commands) in just one file. Also, it can handles bsome logic because it's a programming language.
How to create it
- Create the file:
$ touch myscript.sh
- Add a shebang at the start of the file. The Shebang line is responsible for letting the command interpreter know which interpreter the shell script will be run with:
$ echo "#!/bin/bash" > myscript.sh
# or
$ your-desired-editor myscript.sh
# write at the first line #!/bin/bash
- Add some commands:
$ echo "echo Hello World!" >> myscript.sh
- Give the file execution mode:
$ chmod +x myscript.sh
- Execute it!
$ ./myscript.sh
Hello World!
More info about shell-scripting can be found here
//changes script file extension is not necessary In linux, script can be executed even without .sh extension. for example test.sh can be executed if we leave it as test. If we keep our script in user/bin then we can use script anywhere.