BASH | INTRO










GNU Bash or simply Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used widely as the default login shell for most Linux distributions and Apple's macOS Mojave and earlier versions





Interactive Shell





The Bash shell is commonly used interactively: 
It lets you enter and edit commands, then executes them when you press the Return key. Many Unix-based and Unix-like operating systems use Bash as their default shell (notably Linux and macOS). The terminal automatically enters an interactive Bash shell process on startup.
Output Hello World by typing the following:





echo "Hello World"
#> Hello World # Output Example





Non-Interactive Shell





The Bash shell can also be run non-interactively from a script, making the shell require no human interaction. Interactive behavior and scripted behavior should be identical – an important design consideration of Unix V7Bourne shell and transitively Bash. Therefore anything that can be done at the command line can be put in a script file for reuse.
Follow these steps to create a Hello World script:






1. Create a new file called hello-world.sh





touch hello-world.sh






2. Make the script executable by running





chmod +x hello-world.sh






3. Add this code:





#!/bin/bashecho "Hello World"






4. Execute the hello-world.sh script from the command line using one of the following:






1)./hello-world.sh – most commonly used, and recommended





2)/bin/bash hello-world.sh





3)bash hello-world.sh – assuming /bin is in your $PATH





4)sh hello-world.sh





For real production use, you would omit the .sh extension (which is misleading anyway, since this is a Bash script, not a sh script) and perhaps move the file to a directory within your PATH so that it is available to you regardless of your current working directory, just like a system command such as cat or ls .






Peace out





@suhaibbinyounis


Post a Comment

Post a Comment (0)

Previous Post Next Post