I want 'me' to equal $whoami , but when I try to do it I just print "whoami" as a string instead of the actual value. Would it be possible to use a pipe to connect the variable and the command?
It must get the user's name using the whoami command and store it in a variable called username . It must take a single parameter which is the name of the file to be searched. It must grep to search the specified file for occurrences of the user's name and print them.
To store the output of a command in a variable, you can use the shell command substitution feature in the forms below: variable_name=$(command) variable_name=$(command [option ...] arg1 arg2 ...) OR variable_name='command' variable_name='command [option ...]
Using variable from command line or terminal You don't have to use any special character before the variable name at the time of setting value in BASH like other programming languages. But you have to use '$' symbol before the variable name when you want to read data from the variable.
Use it like this:
me="$(whoami)"
to store command whoami
output to shell variable me
what about:
me="$USER"
but why should you do this ? It is already an environment variable :-)
echo "$USER"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With