Hi Ubuntu users,
I'm a newbie when it comes to Bash/Shell-scripting. So I have tried to simplify the issue where I'm stuck at with this uname -a example script. What I'm trying to do is to insert a variable containing the flag -a into the command uname with Bash scripting.
The reason for dumbing it down like this, is because I have a much more complex and longer Nmap command containing a mix of double and single quotes, which I'm working on but can't understand and make it work. I will have to create a separate thread for that Nmap command if I get that far with my understanding.
I also used this Shell-script analysis tool, to the best of my abilities which somebody at StackOverflow mentioned. I read a couple of those threads and various Bash tutorials on the Internet. But I couldn't understand how to proceed with this problem.
https://www.shellcheck.net/
concat_3.sh
PHP Code:
#!/usr/bin/bash
endpoint=' -a'
# myvar=`whoami`
# myvar=$(uname -a)
# myvar=$(uname "$1")
myvar=$(uname $1)
# Example 1
echo ""
echo "=== Example 1 ==="
script_1="Argument 1 is: $myvar"
echo "$script_1"
echo ""
# Example 2
echo "=== Example 2 ==="
script_2="Argument 1 is: $1"
echo "$script_2" "$myvar"
echo ""
# Print $myvar and $endpoint
echo '=== Print $myvar and $endpoint ==='
echo "$myvar" "$endpoint"
echo ""
# Example 3
endpoint3=' -a'
echo "=== Example 3 ==="
script_3="uname $1"
echo "$script_3" "$endpoint3"
echo ""
output
Code:
$ bash concat_3.sh
=== Example 1 ===
Argument 1 is: Linux
=== Example 2 ===
Argument 1 is: Linux
=== Print $myvar and $endpoint ===
Linux -a
=== Example 3 ===
uname -a