Question

I am having trouble on what exactly to write so I can make the script work,...

I am having trouble on what exactly to write so I can make the script work, can someone show how to properly do it?

Use the vi editor to enter the following script (name this file testscript):

#!/bin/bash

#script to demonstrate :  reading arguments from a command line &

#                                      interactively from within script

#                                      selection (if… then… else…. fi)

#                                      iteration (for loop)

# USE FILES ENTERED ON THE COMMAND LINE

echo The script you are running is $0

echo The number of lines in file $1 is: 

wc –l $1                                #(note that switch is L and not the number one)

echo The number of words in file $2 is: 

wc –w $2

# READ INPUT FROM THE KEYBOARD AND PERFORM COMPARISON

echo Enter Your Age :

read age

if  [  $age  -le  30  ]

     then

            echo  “you are young”

     else

            echo “you are over 30!”

fi

# USE FOR LOOP TO READ THROUGH FILES PASSED AS ARGUMENTS

for i in $@

do

        echo counting file number $i

done
  • to execute the script:
    • chmod a+x testscript
    • . /testscript IFT250 sorted IFT250.dups IFT250.dups2
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

As it is clearly not mentioned in the question that whether i need to write a shell script or not so as per my understanding i have written the demo script that print all the arguments passed in the command line.

=============================================================

Script:

=============================================================

#!/bin/bash
#script to demonstrate : reading arguments from a command line &
# interactively from

n=$#

echo "Number of argument passed = $n"

echo -e "Printing all the argument passed"

for i in $*

do

echo "$i"

done


============================================================

Sample Output:

=============================================================

Kindly Check and Verify Thanks...!!!

Add a comment
Know the answer?
Add Answer to:
I am having trouble on what exactly to write so I can make the script work,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script,...

    LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script, we will iterate through all files in the current directory print out their name using the for loop. Example (do not type yet): foriin*;do …;done where the…does some operation on$I, which stands for the current file. To do this, enter the following in your script4.sh file:           #!/bin/bash           for i in *; do                echo $i           done Once the above works, change the for loop to...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command no...

    Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command not found line 10: syntax error near unexpected token `then' line 10: `then' ------------------------------- #!/bin/bash if [ $# != 1 ] then echo "Usage: myScript.sh " exit 1 fi if [ -f $1 ] then awk ' BEGIN...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • 5.Create two files also called file file1 and file2 in testdir_2 Use the ls -lR to show you created the directories 6. Change the permission of the files in the directories below and show their permi...

    5.Create two files also called file file1 and file2 in testdir_2 Use the ls -lR to show you created the directories 6. Change the permission of the files in the directories below and show their permissions testdir/testdir_1/file1 where owner has read and execute permissions testdir/testdir_1/file2 where where owner has read, write and execute permissions. Group has read only permissions 7. Create a directory called newdir/newdir_1/newdir_2 copy the file testdir/testdir_1/file1 to this directory Change the permisions of the file to owner,...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • I need this done ASAP. Please write a bash shell script that does the following: Prints...

    I need this done ASAP. Please write a bash shell script that does the following: Prints out how many users are logged on. This can be accomplished using who and wc. Prints out a list of currently logged on users. This can be accomplished using who, grep, regular expressions, and echo. Prints out how many processes you have running from past days, and a list of those jobs. Use `whoami` to get your username. Run ps -ef and see how...

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT