Question

In: Computer Science

Task: 2.1 : Shell Scripting Task1 :Traditional hello world script Open terminal create Lab01 directory and...

Task: 2.1 : Shell Scripting

Task1 :Traditional hello world script

  1. Open terminal create Lab01 directory and use cd command to move into the directory
  2. Open a new file script hello.sh using vi editor

# vi hello.sh

  1. Type the following lines

#!/bin/bash           echo Hello World    

  1. Save the file and return back to terminal

How to Runhello.sh

Adding Execute Permission

  1. Checking current permission       

# ls -la hello.sh

  1. Adding Execute permission

# chmod u+x hello.sh  

  1. Check whether execute permission is added

# ls -la hello.sh

  1. Running or executing the script  

# ./hello.sh

Description : This script has only two lines. The first indicates the system which program to use to run the file. The second line is the only action performed by this script, which prints 'Hello World' on the terminal.

Task2.2 :In this lab exercise, you will create a bash shell script and execute it. The studentswillalso use bash variables to customize their shell prompts.

  1. Open a new file script calc.sh using vi editor

# vi calc.sh

  1. Type the following lines

#!/bin/bash #a simple script

echo "$1 + $2 = $(($1 + $2)) "

  1. Save the file

  1. Change the permissions of calc.sh to executable with

#chmod u+x calc.sh

  1. From the terminal, run the script with  

# ./calc.sh 2 2

Task 2.3: Write a script that will create a file that is named when you execute the shell script and direct the o/p of ls to that file

  1. Open a new file script myshell.sh using vi editor

# vi myshell.sh

  1. Type the following lines

#!/bin/bash touch $1 ls > $1

  1. Add the execute permission
  2. Run the script

# ./myshell.sh testfile

  1. Check whether testfile is created
  2. Check the contents of the file
  3. Run the script again and create a testfile1

Task 2.4 : Write a script that will create a file using today’s date and the date format is ddmmmyy.dat

  1. Open a new file script date.sh using vi editor # vi date.sh
  2. Type the following lines

#!/bin/bash touch   `date +%d%b%y`.dat FILENAME=`date +%d%b%y`.dat touch $FILENAME

  1. Add the execute permission
  2. Run the script

#./date.sh

  1. Check whether file is created

Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created

  1. Open a new file script creafile.sh using vi editor

# vi creafile.sh

  1. Type the following lines

#!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created”

  1. Add the execute permission
  2. Run the script

#./creafile.sh

  1. Enter the file name you want to create
  2. Check whether file is created

Task 2.6 : In this exercise, you will create a script to echo users, based on a list of usernames in a file.

  1. create a new file called userlist.

#viuserlist

  1. Insert a short list of usernames, such as the following. Make sure that none are the names of existing users.

moe larry curly

binny

  1. create a script file userscript.sh and type the following lines

#!/bin/bash

for TheUSER in $(cat userlist) do

    echo The user is $TheUSER

done

  1. Add the permissions and run the script

Solutions

Expert Solution

Task: 2.1 : Shell Scripting

For insert the text in vi editor use i button to insert.

For saving the file in vi editor use :wq to save and quit from vi editor

File content of hello.sh is:

#!/bin/bash #a simple script

echo "$1 + $2 = $(($1 + $2)) "

Task2.2:

File content of calc.sh is:

#!/bin/bash #a simple script

echo "$1 + $2 = $(($1 + $2)) "

Task 2.3:

myshell.sh:

#!/bin/bash #a simple script

touch $1 ls > $1

Check the directory Lab01

testfile is crated

Task 2.4 :

date.sh file content is:

#!/bin/bash

touch `date +%d%b%y`.dat

FILENAME= `date +%d%b%y`.dat

$FILENAME

Task 2.5:

creafile.sh file content is:

#!/bin/bash

echo 'enter a file name: '

read FILENAME

touch $FILENAME

echo "$FILENAME has been created"

Task 2.6:

userlist file content is:

moe

larry

curly

binny

userlist.sh file content is:

#!/bin/bash

for TheUSER in $(cat userlist)

do

    echo The user is $TheUSER

done


Related Solutions

this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Open the terminal and using vi/vim create a new script and name it lab6 Insert at...
Open the terminal and using vi/vim create a new script and name it lab6 Insert at the top of your file a comment with your name, class and section number (e.g. #John Doe, EMT 2390L - OL123). In this lab you are going to display a multiplication table of a number entered by the user between 2 and 10 using a for loop and without using multiplication. The table will display the values that are less than or equal to...
In this lab, you will learn how to create shell scripts using the Bourne Shell Scripting...
In this lab, you will learn how to create shell scripts using the Bourne Shell Scripting language. The student will have to do research on the Bourne Shell Scripting language and then writ a script that asks the First Name , Last Name, Age, and Country of origin of the student and then print out these items in a statement Then the students will write a 3 to 4-page paper (not including the title and references pages) describing how the...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it;...
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it; Provide command and screenshot. b) Create a hard link named “file2” linked to “file1”; c) Create a soft link named “soft1” linked to “file1”; create another soft link named “soft2” linked to “file2”. d) View information of the 4 files (what command should you use to produce output) – how do you verify which file is a hard link and which file is a...
Use CYGWIN TERMINAL to create this script. COPY AND PASTE the screenshot. Script 1: 1.   Perform...
Use CYGWIN TERMINAL to create this script. COPY AND PASTE the screenshot. Script 1: 1.   Perform a ls -al on the files within the user's home directory and save it to a file called ls.dat within your ~ directory 2.   Save the tree information for the /home directory in a file called tree.dat within your ~directory 3.   Create a new directory in your home directory called "backups" 4.   Move the files you just created to the new directory 5.   Rename...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh),...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh), (Arch.sh) and (Buzz.sh). The first script Main.sh must have two subroutines. The First Subroutine will display the following messages on the screen: 1-Display User login name, date and time. 2-Display System boot time. 3-Working path and Shell type 4-Display Home directory and number of files and directories in your Home. 5-Message describing briefly the requited tasks.
In this task, you will create a Python script in which you will practice reading files...
In this task, you will create a Python script in which you will practice reading files in Python and writing them to a new output file. Construct a text file called Py4_Task3_input.txt that has the following lines: 4 Sandwiches 04 July 2020 Pasta 31 October 2014 Hot Dogs 15 November 2005 Tacos 25 December 1986 The first line of the file represents the number of lines in the data file. Write a loop that reads in each additional line (one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT