Posts

Showing posts from June, 2017

Grep Command in Unix Shell script

Consider the below file with data cat sample_file.txt linux storage unix distributed system linux file server debian server fedora backup server       Let see the bash script that prints the lines which contain the word server in it. The bash script code is shown below:  vi grep_script.sh #!/bin/bash WORD=server INPUT_FILE=sample_file.txt grep "$WORD" $INPUT_FILE   Now we will execute this script and see what the output is > bash grep_script.sh linux file server debian server fedora backup server

We will see how to pass these as arguments from the command line to the script. The bash script is:

#!/bin/bash INPUT_FILE=$1 WORD=$2 grep "$WORD" $INPUT_FILE Now run the script as shown below: bash grep_script_command_line.sh sample_file.txt server

Write a Bash script which accepts name as input and displays a greeting: "Welcome (name)"

read name echo "Welcome $name"

Your task is to use for loops to display only odd natural numbers from to .

for ((i=1;$i<100;i=$i<2)) do echo $i done