Variable with brackets “$()” The 2019 Stack Overflow Developer Survey Results Are...
Button changing its text & action. Good or terrible?
Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?
Correct punctuation for showing a character's confusion
Why is the maximum length of OpenWrt’s root password 8 characters?
Short story: man watches girlfriend's spaceship entering a 'black hole' (?) forever
What is this sharp, curved notch on my knife for?
Is Cinnamon a desktop environment or a window manager? (Or both?)
Alternative to の
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
Deal with toxic manager when you can't quit
Can a flute soloist sit?
How can I have a shield and a way of attacking with a ranged weapon at the same time?
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Is it safe to harvest rainwater that fell on solar panels?
Cooking pasta in a water boiler
How do you keep chess fun when your opponent constantly beats you?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Ubuntu Server install with full GUI
Can there be female White Walkers?
Are spiders unable to hurt humans, especially very small spiders?
How much of the clove should I use when using big garlic heads?
Kerning for subscripts of sigma?
"as much details as you can remember"
Is it okay to consider publishing in my first year of PhD?
Variable with brackets “$()”
The 2019 Stack Overflow Developer Survey Results Are InProblem with script substitution when running scriptChange Gsetting with script on Logoutfind does not work with my variableWhat does >> or double Angle brackets mean?Defining and incrementing a variable in bashRename directory using a variableBrackets, Braces, Curly Brackets in BashFor loop with variable incrementwoof does not work with files whose names contains spaces or bracketsAssigned variable for pipeline is not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Previously a member @Evan Chen, wrote this script :
#!/bin/bash
while [ true ]
do
currentoutput="$(lsusb)"
if [ "$currentoutput" != "$lastoutput" ]
then
echo "" date and Time >> test.log
date +%x_r >> test.log
lastoutput="$(lsusb)"
lsusb >> test.log
fi
sleep 5
done
I'm a newbie, trying to learn fast and I got a question about the variable's brackets.
Put a variable between $(), I get it, but why the brackets are needed, even in the if statement ?
To make a nested command ??
Thanks
bash scripts
New contributor
add a comment |
Previously a member @Evan Chen, wrote this script :
#!/bin/bash
while [ true ]
do
currentoutput="$(lsusb)"
if [ "$currentoutput" != "$lastoutput" ]
then
echo "" date and Time >> test.log
date +%x_r >> test.log
lastoutput="$(lsusb)"
lsusb >> test.log
fi
sleep 5
done
I'm a newbie, trying to learn fast and I got a question about the variable's brackets.
Put a variable between $(), I get it, but why the brackets are needed, even in the if statement ?
To make a nested command ??
Thanks
bash scripts
New contributor
add a comment |
Previously a member @Evan Chen, wrote this script :
#!/bin/bash
while [ true ]
do
currentoutput="$(lsusb)"
if [ "$currentoutput" != "$lastoutput" ]
then
echo "" date and Time >> test.log
date +%x_r >> test.log
lastoutput="$(lsusb)"
lsusb >> test.log
fi
sleep 5
done
I'm a newbie, trying to learn fast and I got a question about the variable's brackets.
Put a variable between $(), I get it, but why the brackets are needed, even in the if statement ?
To make a nested command ??
Thanks
bash scripts
New contributor
Previously a member @Evan Chen, wrote this script :
#!/bin/bash
while [ true ]
do
currentoutput="$(lsusb)"
if [ "$currentoutput" != "$lastoutput" ]
then
echo "" date and Time >> test.log
date +%x_r >> test.log
lastoutput="$(lsusb)"
lsusb >> test.log
fi
sleep 5
done
I'm a newbie, trying to learn fast and I got a question about the variable's brackets.
Put a variable between $(), I get it, but why the brackets are needed, even in the if statement ?
To make a nested command ??
Thanks
bash scripts
bash scripts
New contributor
New contributor
New contributor
asked 5 mins ago
ShankharaShankhara
1
1
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The following runs the external command command
and returns its output.
"$(command)"
Without the brackets, this would look for a variable instead of running a command:
"$variable"
As for the difference between $variable
and "$variable"
, this becomes relevant when $variable
contains spaces. When using "$variable"
, the entire variable contents will be interpreted as a single string. When using $variable
they may expand into multiple arguments.
add a comment |
In currentoutput="$(lsusb)"
lsusb is not a variable, it is a command. What this statement does, it executes lsusb
command and assigns its output to currentoutput
variable.
Older syntax for this was
currentoutput=`lsusb`
you can find it in many examples and scripts
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Shankhara is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1133173%2fvariable-with-brackets%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The following runs the external command command
and returns its output.
"$(command)"
Without the brackets, this would look for a variable instead of running a command:
"$variable"
As for the difference between $variable
and "$variable"
, this becomes relevant when $variable
contains spaces. When using "$variable"
, the entire variable contents will be interpreted as a single string. When using $variable
they may expand into multiple arguments.
add a comment |
The following runs the external command command
and returns its output.
"$(command)"
Without the brackets, this would look for a variable instead of running a command:
"$variable"
As for the difference between $variable
and "$variable"
, this becomes relevant when $variable
contains spaces. When using "$variable"
, the entire variable contents will be interpreted as a single string. When using $variable
they may expand into multiple arguments.
add a comment |
The following runs the external command command
and returns its output.
"$(command)"
Without the brackets, this would look for a variable instead of running a command:
"$variable"
As for the difference between $variable
and "$variable"
, this becomes relevant when $variable
contains spaces. When using "$variable"
, the entire variable contents will be interpreted as a single string. When using $variable
they may expand into multiple arguments.
The following runs the external command command
and returns its output.
"$(command)"
Without the brackets, this would look for a variable instead of running a command:
"$variable"
As for the difference between $variable
and "$variable"
, this becomes relevant when $variable
contains spaces. When using "$variable"
, the entire variable contents will be interpreted as a single string. When using $variable
they may expand into multiple arguments.
answered 2 mins ago
thomasrutterthomasrutter
27.3k47089
27.3k47089
add a comment |
add a comment |
In currentoutput="$(lsusb)"
lsusb is not a variable, it is a command. What this statement does, it executes lsusb
command and assigns its output to currentoutput
variable.
Older syntax for this was
currentoutput=`lsusb`
you can find it in many examples and scripts
add a comment |
In currentoutput="$(lsusb)"
lsusb is not a variable, it is a command. What this statement does, it executes lsusb
command and assigns its output to currentoutput
variable.
Older syntax for this was
currentoutput=`lsusb`
you can find it in many examples and scripts
add a comment |
In currentoutput="$(lsusb)"
lsusb is not a variable, it is a command. What this statement does, it executes lsusb
command and assigns its output to currentoutput
variable.
Older syntax for this was
currentoutput=`lsusb`
you can find it in many examples and scripts
In currentoutput="$(lsusb)"
lsusb is not a variable, it is a command. What this statement does, it executes lsusb
command and assigns its output to currentoutput
variable.
Older syntax for this was
currentoutput=`lsusb`
you can find it in many examples and scripts
answered 19 secs ago
marosgmarosg
44437
44437
add a comment |
add a comment |
Shankhara is a new contributor. Be nice, and check out our Code of Conduct.
Shankhara is a new contributor. Be nice, and check out our Code of Conduct.
Shankhara is a new contributor. Be nice, and check out our Code of Conduct.
Shankhara is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1133173%2fvariable-with-brackets%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown