Wednesday, May 8, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 5288  / 1 Year ago, tue, april 18, 2023, 11:38:46

The output of



# ls


and



# echo $(ls)


are the same. What exactly does the $ sign and the parenthesis mean?



Also, what is going on a technical level that causes the output of these two commands to be the same?


More From » command-line

 Answers
5

This is command substitution for bash.




Command substitution allows the output of a command to replace the
command itself. Command substitution occurs when a command is enclosed
as follows:



 $(command) or

`command`



http://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution



More:



http://tldp.org/LDP/abs/html/commandsub.html



http://wiki.bash-hackers.org/syntax/expansion/cmdsubst



And a good example similar to your question:



http://bashshell.net/shell-scripts/using-command-substitution-in-a-bash-shell-script/


[#41653] Wednesday, April 19, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
skipu

Total Points: 366
Total Questions: 114
Total Answers: 112

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
skipu questions
Sun, Dec 26, 21, 05:25, 2 Years ago
Wed, Oct 6, 21, 10:26, 3 Years ago
Sun, Oct 31, 21, 02:01, 3 Years ago
Tue, Feb 14, 23, 19:48, 1 Year ago
;