Question

In: Computer Science

Unix Create a script that will declare an array and assign four values from the command...

Unix

Create a script that will declare an array and assign four values from the command line.

1. Use these four values - Paul, Ringo, George, John, - in that order

2. Display the content of the array, displaying the values in this format and this order

The first array value is "John"

The second array value is "Paul"

The third array value is "George"

The fourth array value is "Ringo"

Solutions

Expert Solution

Code:

Output:

Raw code:

# taking command line argument to a list
if [ "$#" -eq 0 ]; then
  array=( defaultarg1 defaultarg2 )
else
  array=( "$@" )
fi

# changing the order of elements
array=( ${array[3]} ${array[0]} ${array[2]} ${array[1]} )

# taking another array
strings=( "first" "second" "third" "fourth")

# lenght of array
len=${#array[@]}

# printing all elements
for (( i=0; i<$len; i++ )); 
do 
        echo "The ${strings[$i]} array value is \"${array[$i]}\"" ; done

NOTE:
   If You Have Any Doubts Feel Free To Comment In The Comment Section.
   Do Vote (LIKE).


Related Solutions

In C++ Declare an integer array of size 20 and assign the array with 20 randomly...
In C++ Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100]. Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program. Finally, print out the shuffled array. (25 points) #include<iostream> using namespace std; const int NUM = 20; int main() {      ...
Java: Declare a two-dim array that represents five students with four test scores. Assign 100 for...
Java: Declare a two-dim array that represents five students with four test scores. Assign 100 for all tests to all students. Change the 3rd student’s test 2 to 50. Change the last student’s last test to 87 Print out all test scores. Calculate the total points of all tests of all students
Declare an integer array of size 20 and assign the array with 20 randomly generated integers...
Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100]. Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program. Finally, print out the shuffled array. (25 points) #include<iostream> using namespace std; const int NUM = 20; int main() {             //...
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
unix/Linux Create a tar command using the man command and the link referred to in To...
unix/Linux Create a tar command using the man command and the link referred to in To Practice and Explore: Text File Utilities #9. Preliminaries Use the man pages to learn more about tar Review the links referred to in To Practice and Explore: Text File Utilities #9 to see examples of using tar command Perform Use tar "to stuff" three files and then "unstuff" them into a new directory. Include the -v option. Task ll to show the original 3...
Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
Declare a 3x4 multidimensional array. Receive values for eachelement from user. Find the smallest value...
Declare a 3x4 multidimensional array. Receive values for each element from user. Find the smallest value in the multidimensional array, display its index and value, use array access operator [ ]. Find the largest value in the multidimensional array, display its index and value, use pointers. Write C code.
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...
[JAVA SCRIPT] Please create an array of student names and another array of student grades. Create...
[JAVA SCRIPT] Please create an array of student names and another array of student grades. Create a function that can put a name and a grade to the arrays. Keep Read student name and grade until student name is “???”. And save the reading by using a function Create another function to show all the grade in that object. Create the third function that can display the maximum grade and the student’s name. Create a sorting function that can sort...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT