I need to print command in variable. I know how to do it:
a=$(uname -r)
echo $a
But if I have more commands in script and I need to print only kernel, how can I do it?
./script.sh -k
--------
kernel=5.13.0-28-generic
And also what if I want to print only 'help' ? Thanks!
a=$(./script.sh -k)
– jesse_b Apr 03 '22 at 13:16a=$(uname -r)
b=$(nproc)
If I start it, it write me kernel version and cpu nums, but what if I want to start script with./script.sh -k
to print only kernel version without nproc, how I can do it? – lolilaliaa Apr 03 '22 at 13:20-k
is the only possible option or argument you'd ever send to your script, it can be simplified down toif [[ "$1" != "-k" ]] ; then b=$(noproc) ; echo $b ; fi
, or even just[[ "$1" == "-k" ]] && exit
on the line afterecho $a
, but if your options and script are more complicated than that, check steeldriver's link. – frabjous Apr 03 '22 at 14:11