Create and Run Bash Script

This section provides a tutorial example on how to create and run a Bash shell script file.

Bash is also a scripting language. You can enter multiple Bash commands in a file to create a Bash script, which can be invoked later to execute those commands.

1. Use the "cat" command to create "f" script file. Press Ctrl-D to end the input stream.

herong$ cat > f
#!/bin/bash
# f name
echo
echo File list info:
ls -l $1 # list file info
echo
echo Number of lines:
wc -l < $1 # count words in this file
echo
echo File type:
file $1
Ctrl-D 

2. Change permissions of the script file to make it executable.

herong$ chmod 700 f
herong$ ls -l f

-rwx------  1 herong  staff  164 Dec 22 15:06 f

3. Run the script file.

herong$ ./f f 

File list info:
-rwx------  1 herong  staff  166 Dec 22 15:19 f

Number of lines:
      11

File type:
f: Bourne-Again shell script text executable, ASCII text

Table of Contents

 About This Book

 Introduction to Ubuntu Systems

 GNOME - Desktop Interface and Environment

Shell - The Command-Line Interpreter

 What Is Shell

 What Is Bash (Bourne Again SHell)

Create and Run Bash Script

 Bash Command Line Interpretation Steps

 Bash Shell Session Customization

 Command Input/Output Redirection

 Shell Session Command History

 "tmux" - Terminal Multiplexer

 Process Management

 Memory Management

 Files and Directories

 APT (Advanced Package Tool)

 Network Connection on Ubuntu

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Administrative Tasks

 References

 Full Version in PDF/EPUB