Bash Shell Scripting

Bash Shell scripting refers to using the Bash shell for creating scripts and executing commands in UNIX or Linux for fulfilling the user requirements. Scripts also help automate a number of repetitive tasks taking backups, etc.

Q.1 What is meant by a shell in UNIX or Linux?
A shell is a command line user interface between the end user and the kernel. When the user types command in shell, the command is sent to kernel for execution and command output is displayed to
Q.2 List some commonly used shells in Linux or UNIX
Some commonly used shells in Linux or UNIX are Bash, csh, ksh and Bourne.
Q.3 What are soft and hard links in Linux/UNIX?
Soft links are like shortcuts to file in Windows, it is a link to the file and can be placed anywhere on the disk or file system. Hard links link to the inode of the file hence, should be on same file system as the linked file. If the liked file is deleted, soft link becomes inactive as it is now a broken link and linked file cannot be accessed by the path stored in soft link. In case of hard links, as it links to inode hence it still access copy of the linked file, on its deletion.
Q.4 What will pass argument to a script in Bash shell?
Arguments to a script in Bash shell are passed by listing them after script name in double quotes and separated by space as - “Arg1” “Arg2” “Arg3” etc.
Q.5 How does a script in Bash shell will access the command line arguments to the script
Script in Bash shell can access the command line arguments by prefixing $ to the argument number like $1 or $4
Q.6 Specify the utility of $# in a Bash shell script
The $# is used to provide the count of the command line arguments passed to the Bash shell script.
Q.7 How does the shell character: $* and $@ differ in Bash shell
In Bash shell, $* and $@ differ in their treatment towards positional parameters, $*regards them as single string and $@ considers every argument which is quoted as separate argument
Q.8 Which command on Bash shell is used to change group ownership?
chgrp command changes group ownership
Q.9 Which command on Bash shell will show the UNIX or Linux version?
uname -r command is used to show the UNIX or Linux version
Q.10 Which character is used to separate multiple commands entered on the same command line in Bash shell?
The ; character separates multiple commands on the same command line
Q.11 List the command to be given on Bash shell to end a process with ID as 408 without a graceful exit
The kill –9 command will end a process without graceful exit, as: kill –9 408
Q.12 Which regex pattern will match the following words: and, made, named, standard?
a.*d is the correct regex pattern for searching: and, made, named, standard.
Q.13 List the Bash shell command which would search lines 2 through 20 of the file records for the characters 1st and replace them with the characters first?
sed ‘2,20s/1st/first/’ records , is the correct command.
Q.14 List the Bash shell command would separate the file file01 into multiple files, each containing 60 lines
The split command is used to fulfil the task as: split -60 file01.
Q.15 How to send the data from the ls command to the file file01 in Bash shell?
The ls command in Bash shell is used with a pipe for the task as: ls | file01.
Q.16 What redirects stdout and stderr to a file?
|& is used to redirect stdout and stderr to a file on Bash shell.
Q.17 Which Bash shell command, shows the length of time, the system has been running?
The uptime command is used for the purpose.
Q.18 Differentiate between $$ and $! in Bash shell
In Bash shell, $$ and $! differ on process for which process ID is shown by them. $$ lists process ID of current executing process and $! Display process ID of process which just went to background.
Q.19 Which Bash sell command change access permissions
The chmod command on Bash shell is used to change access permissions
Q.20 List the Bash shell command to change file owner and group
The chown command on Bash shell changes file owner and group.
Q.21 Define a zombie process
A zombie process is not active and has died but their exit status has not been updated by their parent process. Zombie process have retains their process ID but are not functional.
Q.22 Which command in used to copy files from a remote machine?
Copying files from remote machines can be done by in-built commands or utilities on Bash shell like – ftp, scp or rync.
Q.23 How to securely connect to a remote machine over HTTP?
Secure connection to a remote machine over HTTP can be done by using the ssh command on Bash shell. The ssh command is used as: ssh username@serverIP -p port , then password is to be provided
Q.24 How will you monitor log files by Bash shell, which store user activity and are continuously updated?
We can use the tail command in Bash shell to monitor log files. The tail command lists the data from end of the file and by default last 10 lines are shown. The syntax for the tail command is: tail –f filename. The output of the tail command can be shown on screen or saved to another file for analysis.
Q.25 How to print text common in two text files: text01 and text02
We can use the comm command in Bash shell to print common text amongst text files: text01 and text02. The command on Bash shell will be as: comm -12 text01 text02 The -1 and -2 are joined, which suppress the display of lines in text01 and text02, and text common to both is shown.
Q.26 How will you print the 7th line of file01, in Bash shell but without the tail and head command
We can use the sed command in Bash shell as: sed –n '7p' file01
Q.27 Which command makes the scripts interactive?
Read command makes the script interactive as it stops the script execution for user input
Q.28 Which command should be executed to make the script executable?
The chmod +x

Get Govt. Certified

Know More
Get Govt. Certified Take Test