DEV Community

Cover image for Continuation to Shell Scripting
Kenneth Aigbuza
Kenneth Aigbuza

Posted on

Continuation to Shell Scripting

Basic Bash commands (echo, read, etc.)

Here is a list of some of the most commonly used bash commands:

cd: Change the directory to a different location.
ls: List the contents of the current directory.
mkdir: Create a new directory.
touch: Create a new file.
rm: Remove a file or directory.
cp: Copy a file or directory.
mv: Move or rename a file or directory.
echo: Print text to the terminal.
cat: Concatenate and print the contents of a file.
grep: Search for a pattern in a file.
chmod: Change the permissions of a file or directory.
sudo: Run a command with administrative privileges.
df: Display the amount of disk space available.
history: Show a list of previously executed commands.
ps: Display information about running processes.

Reading user input

We can read the user input using the read command.

  • read -p* where the p stands for prompt

reading user input
when you run this command on the terminal, it gives the user the option to input his name into it before it echo the last command given to it.
we will have something like this below:

Output
amazing right? let's try out some more commands "using the reading user input"
let's add more options to where users can input more details.

Input

Output
you can play with more examples.

i Tired something different, lets assume you work in an organization, and you are ask to write a script that will ask for a user name and also create a directory for the user, how do you go about it? here it is:

Input

Output
just follow the prompt "ls" to check the folder/directory created.

easy and interesting right?
now let create files in that same directory/folders created for the users.

Input

Output
That is how to create a directory and a file to a user using the name provided.

thanks guys for following through; Day 11 loading very soon

Top comments (1)

Collapse
 
devopsking profile image
UWABOR KING COLLINS

Awesome