LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-14-2018, 11:04 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
BASH -- need help "cleaning up" IF statement


My script reads as follows
Code:
#!/bin/bash

fg="$1"
route=$(exiftool -XMP:WebStatement "$fg")
if [[ $route ~= "some-website.com" ]]; then
	exiv1 -k -dc "$fg"
	echo "GD-Jpeg Comment removed."
	exit 0
else
	picked=$(echo "$route" | cut -d/ -f3)
	echo -e "Picture file downloaded from $picked.\nNo need to strip the comment field."
	echo "Good bye."
fi
I get SC1009, SC1073, and SC1072 errors. I haven't been researching Shellcheck errors for a while, and I have to admit I'm more than a little lost on those pages.

Any help would be much appreciated.

Carver

Last edited by rtmistler; 08-15-2018 at 06:32 AM. Reason: cleaned up inappropriate website content
 
Old 08-15-2018, 12:25 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
i like your honesty.

is this the complete script?

please show us complete command & output for a test run.
 
Old 08-15-2018, 12:37 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
yes, please post exactly what is it, otherwise hard to say anything.
But here is one comment:
Code:
if <condition> then
   do_something
   exit 0
# here you ought to write
fi
# there is no else, just
do_something_else
because exit 0 will definitely not allow to go further.
 
Old 08-15-2018, 03:49 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well I don't get any of the errors you have listed from shellcheck.

The first I do get is that ~= is in the wrong order (maybe a typo) and should be =~

Once this is corrected the only issues are the regex which should be unquoted otherwise taken as a literal, which may be what you wanted.
Then the last is to add an additional backslash for your newline as \n is escaping the 'n' inside quotes so more correct to use \\n to escape the backslash to be an actual backslash

This leads me to be the same as the others in that you need to provide more details and perhaps the full script and arguments being passed in
 
  


Reply



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 script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
Pattern matching with a "case" statement in BASH King V Programming 8 04-27-2006 04:19 PM
C/C++ functions similar to BASH's "cp", "mv", "mkdir", etc? kornerr Programming 10 04-23-2006 09:48 AM
Bash script problems with "if" statement adz Programming 2 05-22-2004 03:34 AM

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

All times are GMT -5. The time now is 08:35 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
Open Source Consulting | Domain Registration