Write Your First Script
Write a small script in your home directory. Use nano hello.sh to create it (or any way you like), give it the right first line, make it executable and run it.
How it works: the terminal below is a real Linux machine running in your browser. Click it and
type. Tasks tick themselves off as you complete them; questions are answered in the box under each task.
Press Reset any time for a fresh machine. Your password on this machine (for
sudo) is student.
Hints
In nano, write the lines, then save with Ctrl+O and quit with Ctrl+X.
Forgot chmod +x? You'll get Permission denied.
Solution explanation
The shebang #!/bin/bash tells Linux to run the file with bash. chmod +x gives it execute permission, and ./hello.sh runs the file in the current folder. $(date) is replaced by the current date when the script runs.
Show solution
cat <<'EOF' > hello.sh
#!/bin/bash
echo "Ahoy, world!"
EOF
chmod +x hello.sh
./hello.sh
cat <<'EOF' > hello.sh
#!/bin/bash
echo "Ahoy, world!"
echo "Today is $(date)"
EOF
./hello.sh