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

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
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...
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.
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...
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...
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
In Java Script how do you code an array with the values and suits of cards...
In Java Script how do you code an array with the values and suits of cards (all 52 cards in a deck) 2 different array one that just has the face values of the card, and the other with the suit value. Then have it randomly give you 1-2 cards from the deck without repeating? (Example: Dealer gives player two cards. Player asks for a hit and the dealer gives a different card, no repeats). Game is Blackjack.
Create your own data type using a C++ structure. Assign values to a variable of that...
Create your own data type using a C++ structure. Assign values to a variable of that data type. Retrieve values from the variable of that data type. Description: In this lab you will choose the statements to create a program that: Creates a brand new data type called "Monster". Once created, creates a variable of type Monster and assign values to the variable and then display the contents. This lab will again take the form of a guided multiple-choice quiz...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT