Bash
Bash Script Basic
Creating and running a bash script step by step:
- (Open your text editor)
- In the editor, add your commands line by line!
echo "number of lines in file:"wc -l some_data.csv
echo "number of characters in file:"
wc -c some_data.csv
- Still in the editor, add this line to the very beginning of your bash script:
#!/usr/bin/env bash(This line is called the shebang. It tells Ubuntu that your script is in bash.)
- Click "10 Quit" in the bottom right corner of the editor and save your file.
- Name your file to demo_script.sh (or whatever you prefer)!
-
- Give permission to yourself to run your script. Type this command :
- Give permission to yourself to run your script. Type this command :
chmod 700 demo_script.sh
- Run your script by typing this on the command line:
./demo_script.sh
Done!
After running the script, your output will be something like this:
number of lines in file:672number of characters in file:11424
You can create various bash scripts (even hundreds of lines long) and even Python or SQL scripts the same way.