Introduction
A Bash script lets you tell your computer to do tasks automatically. It saves time and avoids mistakes when doing the same steps again and again.
A Bash script lets you tell your computer to do tasks automatically. It saves time and avoids mistakes when doing the same steps again and again.
#!/bin/bash echo "Hello, world!"
#!/bin/bash tells the computer this is a Bash script.
echo prints text on the screen.
#!/bin/bash echo "Welcome to my script!"
#!/bin/bash # This is a comment echo "Today is $(date)"
This script prints the classic greeting message to the screen.
#!/bin/bash # Print a greeting message echo "Hello, world!"
Make sure to give your script permission to run by typing chmod +x scriptname.sh.
Run your script by typing ./scriptname.sh in the terminal.
Comments start with # and help explain your code.
Bash scripts automate tasks by running commands in order.
Start scripts with #!/bin/bash to tell the system to use Bash.
Use echo to show messages on the screen.
#!/bin/bash in a Bash script?#!/bin/bash is called a shebang and tells the system which interpreter to use.echo is used to print text to the screen.echo "Hello, World!" correctly prints the message with quotes around the string.#!/bin/bash echo "Start" echo "End"
echo command prints text followed by a new line by default.#!/bin/bash echo Hello World
echo properly.echo prints text; date prints current date and time.echo correctly and calls date without errors.Pass the test and this pattern moves unknown