LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2016, 01:10 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 235

Rep: Reputation: Disabled
View bash interpretation of command but not executing the command


When I ran this command:
Example:
$ cat /etc/group | grep 'adm|cdrom|sudo|dip|plugdev|lpadmin|sambashare'

I get no result. Thus have no idea of what is wrong.
Then I have to search online for solution..... sometimes it can consumes a lot of time.

When I ran this it works:
$ cat /etc/group | grep 'adm\|cdrom\|sudo\|dip\|plugdev\|lpadmin\|sambashare'

So it occurs to me that there maybe a tool to let us see result of bash interpretation of the input (as in a Bash preprocessor or a Bash linter, for lack of a better description) BEFORE it sends the command to kernel for execution.

Is such tool available?
How do I do that?
 
Old 03-02-2016, 01:21 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Bash made zero interpretations as the string is quoted with single quotes. Your issue is that by default grep does simple regular expression interpretation but using the pipe is an extended feature.
Hence you needed to use the -E switch for grep.
 
1 members found this post helpful.
Old 03-02-2016, 01:29 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,957

Rep: Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267
Sort of. You can use the command "set -x" to cause bash to display each command as it is being sent to the kernel. (Use "set +x" to turn that back off.) The command does get executed, but at least you get to see what was sent.

In this case, though, your problem is not with bash but with the grep command itself. The "|" character is not special in basic regular expressions. You either have to use "\|" or else use the "-E" option or egrep to indicate that the "|" character is special and indicates OR-ing.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash covertly executing command sunoc Linux - Newbie 6 04-08-2015 08:30 AM
Executing command in bash script as a different user? homer_3 Programming 6 03-14-2014 11:47 AM
bash script: executing string command chuckj Programming 8 06-17-2010 08:22 AM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 12:21 PM
Trivial bash question - executing $COMMAND atom Programming 4 06-05-2005 05:17 AM


All times are GMT -5. The time now is 06:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration