If you're typing directly at a shell you can
echo "I should have studied"
To create a script, all you do is put the commands you want to be run into a (text) file and use that file:
Using you preferred UNIX/Linux editor, create the file study
. You can use any name you like (including one with a .sh
suffix if you prefer). Add these two lines to it
#!/bin/bash
echo "I should have studied"
The first line declares that it's a bash
shell script. You don't need to filter the output with grep
as the echo
command does enough all by itself. (Also notice you don't type the leading $
; some people use this on StackExchange and other sites to show they're typing a command but personally I think it's confusing.) Now make the file executable so it can run like any other program on the system
chmod +x study
And run it
./study
The leading ./
tells the shell to look for the command in the current directory. If the script was in a system directory or otherwise in your search path ($PATH
) you would be able just to type its name, study
to run it - just like any other command.
For syntax checking, don't be afraid to use https://shellcheck.net/ as and when your scripts start to develop.