Question

Write a script which receives a list of strings as parameters. Input an “ index string...

Write a script which receives a list of strings as parameters. Input an “ index string ”. Iterate through the list of strings and apply the `expr index …` operation on each string using the index string as the index. Output the string and the result of the index operation. When done, run it passing the string

abacab foxtrot duke trespass

and input the index string of abcd. Your output should be abacab 1, duke 1, foxtrot 0, trespass 6.

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

read the strings using the below command

read -a arr

thus arr will strores the strings.

Now read key string

read key

now for each string in a run a for loop.

for a in ${arr[@]}
do 
  echo 'expr index $key $a'
done
Add a comment
Know the answer?
Add Answer to:
Write a script which receives a list of strings as parameters. Input an “ index string...
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
  • Write a function rm_multiple() that takes two parameters as input (a list of strings, and a...

    Write a function rm_multiple() that takes two parameters as input (a list of strings, and a list of strings to remove from the list) and returns a new list with the items removed. # Define function in this cell def rm_multiple(strings,remove_list): l = [10,20,40,50] #use to delete an element in the list for string in strings: strings= l if string not in remove_list: lst.append(string) # Edit the code here to call your function in this cell items = [10,20,40,50] to_remove...

  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python

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

  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The...

    JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

  • Write a function findEvens that takes an integer, n, as input and returns the list of...

    Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python

  • 2a) Write a method countEvens that takes an ArrayList of String objects as input and returns...

    2a) Write a method countEvens that takes an ArrayList of String objects as input and returns the number of even length strings contained in the input. For example, if the input is [ one, peach, pear, plum ] then countEvents(inp) should return 2. 2b) Write a method, mirror, that doubles the size of a list of integers by appending a mirror image of the list. For example, given an array list containing [ 1, 5, 2, 6 ], the method...

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