Question

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 not, you can use command chmod to make it executable first. For example, for problem1.sh, you can do the following:
                -bash-4.1$ chmod +x problem1.sh
-bash-4.1$ ./problem1.sh
which will execute the command(s) in the script.

2. Write a script that will use commands echo, date, cal to print the account name of the person executing the script, the date when the script is being tested, and the month.
The following lists the result when I test my script.
-bash-4.1$ ./problem1.sh
asmith is testing this script on Tue Apr 12 23:08:10 MST 2016 in April 2016
Su Mo Tu We Th Fr Sa
                                1 2
3    4     5     6   7   8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
-bash-4.1$

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash
USER=$(whoami)
echo $USER " is testing this script on" `date`
cal -h

Explanation

1st line tell shell to execute this code as bash program

2nd line gets name of userexecuting this script in variable USER using command 'whoami'

$ is used to assign value of whoamito variable USER

echo outputs the concent on shell so $USER prints value of variable USER and the content in ""

date prints todays date and time. It is placed in `` quotes to interpret it as command

cal -h prints calendar of ongoing month and -h turns off highlightof todays date.

OUTPUT

Add a comment
Know the answer?
Add Answer to:
1. Write 4 simple shell scripts. Each question will ask you to write one or more...
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
  • In this assignment, you will demonstrate your ability to write simple shell scripts. This is a...

    In this assignment, you will demonstrate your ability to write simple shell scripts. This is a cumulative assignment that will challenge you to pull together a variety of lessons from throughout the course. 2 The Assignment Every now and then, I find myself with a large number of files that have inappropriate extensions (the set of characters in the file name after the last :') that need to be changed. For example, a complicated C++ program, developed by someone on...

  • 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...

  • (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...

  • 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...

  • Questions Given this data: drwxr-xr-x 2 asmith staff 4096 Feb 6 19:44 scripts Answer questions 6...

    Questions Given this data: drwxr-xr-x 2 asmith staff 4096 Feb 6 19:44 scripts Answer questions 6 through 13. 6. In the line above, what does the d on the extreme left mean or refer to? 7. What does the letter r mean? 8. What does the letter w mean? 9. What does the letter x mean? 10. On what date was the directory in the line above last modified? 11. To whom or what does the leftmost rwx apply? 12....

  • Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell...

    Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell variables, and .profile script file, echo SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME. Do not give just the value of...

  • 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...

  • Round 1: sequence.c This program should read and execute a list of commands from stdin. Each comm...

    Round 1: sequence.c This program should read and execute a list of commands from stdin. Each command and its arguments (if any) will appear on a separate line. For example, if the file "cmdfile" contains the lines: whoami cal 4 2019 echo The time is: date then running 1 /sequence< cmdfile should output your username, a calendar of the month of April, the string "The time is:", and the current date/time, to standard output. Suggested approach: first, make sure you...

  • In this exercise, you will create a script called file_ops.sh that uses the various file operators...

    In this exercise, you will create a script called file_ops.sh that uses the various file operators The file_ops.sh script will Use one command line argument Use four IF THEN statement to compare the first command line argument Determine which file operators to use that produces the following output when the script run with the arguments shown WARNING: In the IF THEN statements, to avoid syntax error messages, there must be a space before and after each bracket and also between...

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