I'm working on a script using bash to determine the os being used and print to the screen the version.
The only line giving me issues is this one, could you please help me?:
I'm working on a script using bash to determine the os being used and print to the screen the version.
The only line giving me issues is this one, could you please help me?:
An alternative is to use
lsb_release -d
for getting the distribution name, or
lsb_release -a
to get all info about the distro.
More info about this linux standard base utility.
You can't have spaces between the two sides of the = sign, and you need to execute the right side as a subcommand (using $() syntax).
current_os=$(cat /etc/*-release | grep CentOS)
With spaces like current_os = ... bash will interpret it as you trying to run a command called current_os.
dos2unix can fix that.dos2unix os-script.txt and try again.Put the commands in backticks (``) and the statement will assign the output of the command.
current_os=`cat /etc/*-release | grep CentOS`
$() is better