If you have ever run any Linux command before, then you have used the shell. I'll explain things to you.īash which is short for “Bourne-Again shell” is just one type of many available shells in Linux.Ī shell is a command line interpreter that accepts and runs commands. Here's a screenshot of all the steps you saw above: Convert your shell script into bash scriptĬonfused? Don't be confused just yet.
That was probably the easiest Hello World program you have ever written, right? You'll see Hello, World! printed on the screen. Now make the file hello.sh executable by using the chmod command as follows: chmod u+x hello.shĪnd finally, run your first shell script by preceding the hello.sh with your desired shell “bash”: bash hello.sh You can use this command in the terminal directly but in this test, you'll run this command through a shell script. So, basically you are using the echo command to print "Hello World". If you are using a desktop Linux, you may also use a graphical text editor like Gedit to add the text to this file. You can also use a terminal-based text editor like Vim, Emacs or Nano. Press Ctrl+D to save the text to the file and come out of the cat command. Insert the following line in it by typing it in the terminal: echo 'Hello, World!' Now inside this 'scripts directory', create a new file named hello.sh using the cat command: cat > hello.sh Let’s first create a new directory named scripts that will host all our bash scripts.
#How to make a new file in bash how to
Let me show you how to create a simple bash shell script, how to run a bash script and what are the things you must know about shell scripting. It may be a simple backup of a directory or it could be cleaning up temporary files or it can even be cloning of a database.Īutomating a task is one of the many useful scenarios where you can leverage the power of bash scripting. You will often find yourself repeating a single task on Linux over and over again. If you have to do it more than once, automate it!