Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-02-2016, 01:10 PM   #1
Registered: Nov 2015
Posts: 397

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

When I ran this command:
$ 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
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,760

Rep: Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050
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
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 4,328

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:25 PM.

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