Some error occured while loading page for you. Please try again.
Sort 27 Discussions, By:
Please Login in order to post a comment
Why is the read syntax the only correct answer to this question? Why not the $1 alternative?
The input comes from stdin, not comand line arguments
Humm, thanks, didn't know this only correct answere i did also it with $1 with no success .. theses tests are limited
echo "Welcome Dan"
I don't understand why they had to write "script which accepts" instead of "script which reads.
printf "Welcome "
sed -r 's/(.*)/Welcome \1/g'
Hi! I'm new to this. Can you please explain a bit this command?
I'm capturing the contents of stdin using (.*) regexp which can be referenced using \1 where \1 refers to 1st captured group and then prepending the text with "Welcome".The syntax is s/[text]/[replacement]/
Got it. Thanks!
and what's that '/g' for?
Global Replacement. That's not needed here though
new to shell, very incredible
xargs -I ^ echo "Welcome" ^
I have a tick in every test case but when retunr back to the bash tutorials page it doesnt show thus question as fully solved?
checking this; it's a bug on our end. will fix
bug still not fixed
can you please check now? It will be fixed.
3 years and it still hasn't been fixed.
same here :(
here is the answer:
echo "Welcome $name"
echo "Welcome $(</dev/stdin)"
will also work
Can you explain this a bit, please?
Whenever you use something like `$(command) in bash, you're creating a new sub-shell for that command. The input is obtained in that subshell, and the output replaces the entire $(command)` section in the original shell. Essentially think of it like executing a command first and then putting the ouput in place of the bracketed section.
Now, </dev/stdin is just redirecting the input from the subshell. So, whatever is entered in the subshell (sample inputs from the test-cases) gets sent (and replaces) $(</dev/stdin).
I wrote exactly the same thing but it keeps saying it's wrong !!
I dont know why but in Ubuntu 18 it works just by doing
echo 'Welcome' $1
Here is the answer :
read name; echo "Welcome $name"
echo $str1 $test
One new solution: sed -r 's/\w+/Welcome &/g'