Skip to main content
edited body
Source Link
ravery
  • 6.9k
  • 5
  • 23
  • 41

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

###Example 3 -- Variable command expansion

This can also be used to allow user input in a script. For example say I have a script that executes a file, I can allow the user to specify where the file is and save it as path. Then do:

exec $(path)$path/file.sh

If path="/home/me", then the command would expand to:

exec /home/me/file.sh

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

###Example 3 -- Variable command expansion

This can also be used to allow user input in a script. For example say I have a script that executes a file, I can allow the user to specify where the file is and save it as path. Then do:

exec $(path)/file.sh

If path="/home/me", then the command would expand to:

exec /home/me/file.sh

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

###Example 3 -- Variable command expansion

This can also be used to allow user input in a script. For example say I have a script that executes a file, I can allow the user to specify where the file is and save it as path. Then do:

exec $path/file.sh

If path="/home/me", then the command would expand to:

exec /home/me/file.sh
added another example
Source Link
ravery
  • 6.9k
  • 5
  • 23
  • 41

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

###Example 3 -- Variable command expansion

This can also be used to allow user input in a script. For example say I have a script that executes a file, I can allow the user to specify where the file is and save it as path. Then do:

exec $(path)/file.sh

If path="/home/me", then the command would expand to:

exec /home/me/file.sh

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning

###Example 3 -- Variable command expansion

This can also be used to allow user input in a script. For example say I have a script that executes a file, I can allow the user to specify where the file is and save it as path. Then do:

exec $(path)/file.sh

If path="/home/me", then the command would expand to:

exec /home/me/file.sh
Source Link
ravery
  • 6.9k
  • 5
  • 23
  • 41

$ means to substitute the value of the following expression. I can be used with variables or commands. To use it with commands, parenthesis are placed around the command.

###Example 1 - variables:

x=hello
echo $x

this will print "hello" in the terminal

###Example 2 - commands

Say I have a file named hello.txt with the contents:

Hello
world.
Good
Morning

Then I can do:

echo $(cat hello.txt)

the output would be:

Hello world. Good Morning