LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2019, 11:47 AM   #1
hallomoto
Member
 
Registered: Nov 2018
Posts: 30

Rep: Reputation: Disabled
Shell script linux command not found for uname -a


check.sh: line 8: Linux: command not found

When I run the script, it tells me command not found even though the first if statement is fine.

-rwxrwxrwx 1 root root 3706 Apr 16 11:36 check.sh


Code:
function usage {
    echo "$USAGE";
} # end function: usage

# Get OS Release version
if $(uname -a | grep el6); then
    OS_RELEASE_VERS="6"
elif $(uname -a | grep el7); then
    OS_RELEASE_VERS="7"
else
    OS_RELEASE_VERS="0"
fi

Last edited by hallomoto; 04-16-2019 at 11:49 AM.
 
Old 04-16-2019, 12:15 PM   #2
freemedia2018
Member
 
Registered: Mar 2019
Distribution: various automated remasters
Posts: 216

Rep: Reputation: 208Reputation: 208Reputation: 208
Try it without the $( )

Code:
if uname -a | grep el6 ; then
    OS_RELEASE_VERS="6"
elif uname -a | grep el7 ; then
    OS_RELEASE_VERS="7"
else
 
2 members found this post helpful.
Old 04-16-2019, 04:32 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,818

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
A smart alternative is a case-esac
Code:
case $(uname -a) in
( *el6* ) OS_RELEASE_VERS="6"
;;
( *el7* ) OS_RELEASE_VERS="7"
;;
( * ) OS_RELEASE_VERS="0"
esac
Here you need the $( ) because the case needs a string.
The $( ) runs the enclosed shell code and is then substituted by its output.
 
Old 04-16-2019, 08:02 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
While two solutions were given, you may wonder why the original code didn't work.

Code:
if $(uname -a | grep el7); then
...
does the following:
  1. Run the command uname -a | grep el7
  2. Take the output of step 1 and substitute $(...) with it
  3. Execute the if
The output in step 2 looks like this: Linux MACHINENAME KERNELVERSION .... Therefore, the if condition in step 3 becomes
Code:
if Linux MACHINENAME KERNELVERSION ...
which results in a syntax error, since there is no command named Linux.
 
1 members found this post helpful.
  


Reply

Tags
bash, centos7



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] No package 'x11' found No package 'xext' found No package 'xdamage' found No package 'xfixes' found No package 'x11-xcb' found Jigsaw Linux From Scratch 14 02-23-2021 08:35 PM
"Command not found" on my server? “bash: sudo: command not found”? MilesOfRoses Linux - Server 7 04-01-2016 09:19 AM
[SOLVED] complete noob question. "command not found" "command not found" jeanlucpicard Linux - Newbie 4 08-27-2013 02:14 AM
Directory not found; -xzvf not found; Makefile not found RealGomer Linux - Software 4 09-20-2010 10:02 AM
bash: rpm: command not found && sudo: alien: command not found Java_Code Ubuntu 7 07-27-2006 11:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration