Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
12-10-2016, 05:34 PM
|
#1
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Rep: 
|
Simplifying a script
I have a script using Exiftool to remove the software tag, comment header line and date data (in both EXIF and IPTC) from files saved with Gimp 2.8 or 2.9. I want to simplify it so the user needn't go any further than to type the name of the script and the name of the file they want to strip.
The script is called degimp.
Code follows.
Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
echo -e "What file do you want to 'De-GIMP'?"
read -e item
file1=$item
if [ -f "$file1" ]; then
exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
echo "File $file1 is now De-GIMPed."
echo "Check it for yourself with any good tool."
else
echo "Your file is not in this directory."
echo "No file to de-GIMP."
exit 0
fi
IFS=$SAVEIFS
I'm still a little sketchy w/re the whole "$1" thing. Would a line at the top like
work in place of the current prompt?
Carver
Last edited by L_Carver; 12-10-2016 at 05:35 PM.
|
|
|
12-10-2016, 05:54 PM
|
#2
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Code:
$./FileName argument argument
$0 $1 $2
build in Bash assignments for variables.
Code:
Removed this line #!/bin/bash -i, <- I do not know what that -i is for,
but it kept restarting my shell,
so I replaced with this
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
#echo -e "What file do you want to 'De-GIMP'?"
#read -e item
echo "$0"
echo "$1"
#file1="item"
if [ -f "$1" ]; then
# exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1
echo "File $1 is now De-GIMPed."
echo "Check it for yourself with any good tool."
else
echo "Your file is not in this directory."
echo "No file to de-GIMP."
exit 0
fi
IFS=$SAVEIFS
just type in the script name and then file name hit enter.
Code:
userx@voided1.what~>> ./xtest textCattwo
./xtest
textCattwo
File textCattwo is now De-GIMPed.
Check it for yourself with any good tool.
Last edited by BW-userx; 12-10-2016 at 06:16 PM.
|
|
1 members found this post helpful.
|
12-10-2016, 06:23 PM
|
#3
|
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
|
Code:
#!/bin/bash
[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $$(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
Last edited by c0wb0y; 12-10-2016 at 06:43 PM.
|
|
|
12-10-2016, 06:31 PM
|
#4
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
if you want to do more error checking, say for the proper file type.
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
echo "$0"
echo "$1"
c=$1
ext=${c##*.}
echo "ext $ext"
if [[ -f "$1" && "$ext" == 'mp4' || "$ext" == 'mkv' ]]; then
# exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
echo "File $1 is now De-GIMPed."
echo "Check it for yourself with any good tool."
else
echo "Your file is not in this directory."
echo "No file to de-GIMP."
exit 1 <- error is not exit 0
fi
#IFS=$SAVEIFS
if it is the wrong extension then it gets error'ed out.
Code:
userx@voided1.what~>> ./xtest textCattwo.oop
./xtest
textCattwo.oop
ext oop
Your file is not in this directory.
No file to de-GIMP.
note to @c0wb0y
make that one a one liner. 
Last edited by BW-userx; 12-10-2016 at 06:48 PM.
|
|
|
12-10-2016, 06:57 PM
|
#5
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
@c0wb0y
I had to fix your code, I just added mine to yours before checking yours.
Code:
userx@voided1.what~>> ./xtest textCattwo.mkv
./xtest
textCattwo.mkv
ext mkv
./xtest: line 20: syntax error near unexpected token `('
./xtest: line 20: `[[ -f $1 && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $$(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."'
Code:
#!/bin/bash
#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
c=$1
ext=${c##*.}
echo "ext $ext"
[[ -f $1 && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
IFS=$SAVEIFS
|
|
|
12-10-2016, 07:02 PM
|
#6
|
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
|
I know. Those damn extra double quotes and $ sign. These fat fingers. 
Last edited by c0wb0y; 12-10-2016 at 07:03 PM.
|
|
|
12-10-2016, 07:32 PM
|
#7
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by c0wb0y
I know. Those damn extra double quotes and $ sign. These fat fingers. 
|
I fix that then ran it and it still throws an error, so I fixed that and I am not sure what type of files he is using. but that Date I did not fix. getting this error
Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in IFD0:ModifyDate (PrintConvInv)
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
using this code.
Code:
#!/bin/bash
#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
c=$1
ext=${c##*.}
echo "ext $ext"
#[[ -f $1 && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
#### this one
[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F)" $1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
IFS=$SAVEIFS
Just a date format issue NBD, I changed it to this
Code:
-ModifyDate="$(date +%F%T)" $1 <-- exiftool needs file name last to process it.
removing the filename because it kept looking for the annotated file and not the one added on the command line.
Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Error: File not found - 2016-12-10.Pitch.Perfect.2.2015.720p.mp4
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
I do not know what type of file he is actually working with, but just using this line(s)
Code:
#!/bin/bash
#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
c=$1
ext=${c##*.}
echo "ext $ext"
[[ -f $1 && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F%T)" $1 && echo -e "File $1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
#[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F%T)" $1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
IFS=$SAVEIFS
keeping in that error checking for extensions type with and without it I still get the same error.
Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
so it kicks it out and sends the last message.
now if he, the OP can figure all of this out, that'd be a good thing. 
Last edited by BW-userx; 12-10-2016 at 07:34 PM.
|
|
|
12-10-2016, 07:44 PM
|
#8
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
Thanks for all the help and suggestions...
After a little more Google-ing and getting friendly with Stack Exchange, I came up with this re-edit of my original script:
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
file1="$1"
if [ -f "$file1" ]; then
exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
echo "File $file1 is now De-GIMPed."
echo "Check it for yourself with any good tool."
else
echo ""
echo "No file to de-GIMP."
exit 0
fi
IFS=$SAVEIFS
Tested it six times already. No errors (a surprise) and the tags are indeed removed.
I have yet to test the Your file is not in this directory. Which seems unnecessary since the user is naming the file to be de-gimp'ed. I may just edit it out. That sort of thing fits better with a "while read line" kind of loop, which was what I was trying to get away from.
I kept the original script in my execution path, of course and renamed it degimp2. degimp seems more appropriate for the one where the filename follows the command to start the script. I was surprised to not get any bash error messages. I guess the changes I made were up to spec for bash 4.3.
Carver
Last edited by L_Carver; 12-10-2016 at 07:47 PM.
Reason: Flow of sentences; spelling,
|
|
|
12-10-2016, 07:56 PM
|
#9
|
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
|
Hah! Problem with me writing on-the-fly and not reading what those arguments for.
Code:
#!/bin/bash
[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
|
|
|
12-10-2016, 07:59 PM
|
#10
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by c0wb0y
Hah! Problem with me writing on-the-fly and not reading what those arguments for.
Code:
#!/bin/bash
[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } || echo -e "Your file is not in this directory.\nNo file to de-GIMP."
|
I think he wanted to make everything void and null .. anyways, he went to another store to get what he needed after asking us.
|
|
|
12-11-2016, 03:20 PM
|
#11
|
Member
Registered: Oct 2016
Distribution: Slackware
Posts: 310
Rep:
|
I like Cowboy's script the best but why oh why is it all in one line?
To save space?
|
|
|
12-11-2016, 03:30 PM
|
#12
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by Fat_Elvis
I like Cowboy's script the best but why oh why is it all in one line?
To save space?
|
that is the thing about coding, you can one line it. you still need to declare /bin/bash and you output, I just added error checking file types.
|
|
|
12-11-2016, 04:15 PM
|
#13
|
Member
Registered: Oct 2016
Distribution: Slackware
Posts: 310
Rep:
|
Quote:
Originally Posted by BW-userx
that is the thing about coding, you can one line it. you still need to declare /bin/bash and you output, I just added error checking file types.
|
I understand the script, just found his choice to "one line" it funny. Which was probably the intention.
|
|
|
12-11-2016, 05:03 PM
|
#14
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by Fat_Elvis
I understand the script, just found his choice to "one line" it funny. Which was probably the intention.
|
it is just a coding style. if you can do it in one line rather then many lines. well then what is to be said of that?
|
|
|
12-11-2016, 05:27 PM
|
#15
|
Member
Registered: Oct 2016
Distribution: Slackware
Posts: 310
Rep:
|
Quote:
Originally Posted by BW-userx
it is just a coding style. if you can do it in one line rather then many lines. well then what is to be said of that?
|
Didn't mean to be critical, just humorous.
Eh, and I'd need one of those super wide screens to fit that in one line in a text editor. Hehe.
|
|
|
All times are GMT -5. The time now is 07:19 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|