Question

In: Computer Science

⦁   Write a Bash script that prompts for user input and reads a string of text...

⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “.

⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.


  

⦁   Write a short Bas script to display even numbers in a set of 13 to 21 using a WHILE loop technique.

⦁   Re-write your WHILE loop script in previous question using a FOR loop for the same set of numbers of 13 to 21.

Solutions

Expert Solution

1. Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “.

Solution

#!/bin/bash    

# Read the user input     

echo "Enter a string: "  

read input_string

if [ input_string == ' ' ];  

then    

  echo "Enter a not null string: "  

  read input_string

else  

   echo "$input_string"  

fi  

2. Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.

#!/bin/bash  
#Script to print an element of an array with an index of 2 and all elements of array 
  
#declaring the array  
declare -a example_array=( 3 5 13 14  )  
  
#printing the element with index of 2  
echo ${example_array[2]}  
#output is 13

#Printing all the elements  
echo "${example_array[@]}" 
#output is 3 5 13 14

3.Write a short Bas script to display even numbers in a set of 13 to 21 using a WHILE loop technique.

#!/bin/bash  
#While Loop  
  
i=13 
while [ $i -le 21 ]  
do  
rm = $i%=2; 
((i++))
if [[ "$rm" == 0 ]];  
then  
    echo "This is an even Number : $i"  
else
 continue
fi  

done  

4.  Re-write your WHILE loop script in previous question using a FOR loop for the same set of numbers of 13 to 21.

#!/bin/bash  
#for Loop 

for num in {13..21}  
do  
  rm = $num%=2; 
  if [[ "$rm" == 0 ]];  
  then  
    echo "This is an even Number : $i"  
  fi 
done

Hope it will help you, have a great day!!!...

Thank you.


Related Solutions

Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
Write a short bash script that takes in two arguments from a user, asks the user...
Write a short bash script that takes in two arguments from a user, asks the user whether they would like to add, subtract, multiply, or divide. Each of these operations must be a function that returns data.
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT