LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-13-2018, 02:11 AM   #31
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,268

Rep: Reputation: 580Reputation: 580Reputation: 580Reputation: 580Reputation: 580Reputation: 580

Yes the shell does not allow an empty command list.
You can take the : command that does nothing (noop)
Code:
if [[ "$line" == "#"* ]]
then
:   echo "found"
else
   echo "not found"
fi
Or
Code:
: #   echo "found"
Or
Code:
   :
#   echo "found"
 
1 members found this post helpful.
Old 07-13-2018, 03:13 AM   #32
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,223
Blog Entries: 9

Rep: Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617Reputation: 3617
Quote:
Originally Posted by bkelly View Post
this does not work
Code:
if [[ "$line" == "#"* ]];
then
#   echo "found"
else
   echo "not found"
fi
If seems the IF cannot take a null set of commands. That's not very nice.
i think that would be perfectly normal, although i agree with scasey: bash should be able to just skip over that.

even if not, you can always use
Code:
true
or negate the if test:
Code:
if ! [[ "$line" == "#"* ]];
then
   echo "not found"
fi

Last edited by ondoho; 07-13-2018 at 03:14 AM.
 
Old 07-13-2018, 07:16 PM   #33
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 187

Original Poster
Rep: Reputation: 13
Well, this conversation has helped me learn a bit and has resolved my problem.
Thank you for your time and patience.
 
Old 07-15-2018, 03:06 AM   #34
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,505

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
Additionally, if you want to check only if the line begins with #:
Code:
[[ ${line:0:1} == "#" ]]
can be used. (no need to play with *)
 
  


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
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 10:46 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
BASH IF statement kinetik Programming 10 05-07-2006 03:48 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 06:20 PM
bash statement os2 Programming 2 03-20-2005 11:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:51 PM.

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