167k views
4 votes
IN BASH SCRIPT:

Write a code fragment that will take several strings from the user and display them together separated with spaces at the end of execution.

Use a while or until loop, on each iteration of which you read one string from a user and concatenate it with the currently existing string. It should stop when the given string is "DONE".

User Anjandash
by
8.0k points

1 Answer

4 votes

Final answer:

The code fragment is a Bash script that takes several strings from the user and displays them together separated with spaces. It uses a while loop to read each string input from the user and concatenate it with the current string. The execution stops when the given string is 'DONE'.

Step-by-step explanation:

The following code fragment in Bash script will take several strings from the user and display them together separated with spaces at the end of execution:

#!/bin/bash

input_string=""

while [[ $input_string != "DONE" ]]; do
read -p "Enter a string: " input_string
if [[ $input_string != "DONE" ]]; then
final_string+="$input_string "
fi

done

echo "$final_string"

User Marceloquinta
by
8.0k points