Linux - SoftwareThis 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.
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.
Hi Folks, Yet another very simple bash script syntax bit of help needed.
Before I ask just to let you know I've been programming since 1970, BASIC, Fortran, JCL, ADABAS/Natural, PRO-IV, Javascript, HTML, Coldfusion, SQL and now I'm using bash.
It's got great syntax, nice and concise, and i follow the principles, but some of the probably more obvious sides of it escape me - old age??? maybe, maybe not.
Any way I have folder full of mp4 files.
Code:
onk@XEON4 ~/TEST/700k $ ls -al
total 1777376
drwxrwxr-x 2 onk onk 32768 Nov 22 23:25 .
drwxrwxr-x 7 onk onk 430080 Nov 23 14:50 ..
-rw-rw-r-- 1 onk onk 5680963 Jun 23 19:15 10013.mp4
-rw-rw-r-- 1 onk onk 4640217 Jun 23 19:16 10125.mp4
-rw-rw-r-- 1 onk onk 5866973 Jun 23 19:17 10323.mp4
I have a bash executable that displays WxH
Code:
onk@XEON4 ~/TEST/700k $ VWxH.sh 10013.mp4
512x384
onk@XEON4 ~/TEST/700k $ for i in *.mp4; do echo $i VWxH.sh $i ;done
10013.mp4 VWxH.sh 10013.mp4
10125.mp4 VWxH.sh 10125.mp4
10323.mp4 VWxH.sh 10323.mp4
How do I get it to display the mp4's WxH in a for loop?
I guess I could update VHxH.sh to the filename as well as the video dimensions but I really want to know how to wriet the for loop.
This is VWxH.SH
Code:
#!/bin/bash
exiftool -Imagesize -s3 $1
Cheers
Last edited by GPGAgent; 11-25-2018 at 08:50 AM.
Reason: added a bit more
In general:
if you want to check how your script actually working: add set -xv at the beginning of your script
if you wish to check the syntax of your script use shellcheck (www.shellcheck.net).
In general:
if you want to check how your script actually working: add set -xv at the beginning of your script
if you wish to check the syntax of your script use shellcheck (www.shellcheck.net).
Thanks, just what I've been trying but the syntax is getting to me
Code:
onk@XEON4 ~/STUFF/VIDS/TEST $ for i in *.mp4; do echo -n $i " " ; VWxH.sh $i ;s=$(VWxH.sh $i);mv ${i%.mp4} $s-$i; done
1467021_hq.mp4 600x480
mv: cannot stat '1467021_hq': No such file or directory
1684525_hq.mp4 720x480
mv: cannot stat '1684525_hq': No such file or directory
1696132_hq.mp4 1280x720
mv: cannot stat '1696132_hq': No such file or directory
18606_hq.mp4 1280x720
mv: cannot stat '18606_hq': No such file or directory
19586_hq.mp4 640x480
mv: cannot stat '19586_hq': No such file or directory
onk@XEON4 ~/STUFF/VIDS/TEST $ ls -al
total 248244
drwxrwxr-x 2 onk onk 4096 Nov 25 14:55 .
drwxrwxr-x 10 onk onk 323584 Nov 25 18:56 ..
-rw-rw-r-- 1 onk onk 25950908 Sep 30 18:49 1467021_hq.mp4
-rw-rw-r-- 1 onk onk 52623483 Sep 30 19:20 1684525_hq.mp4
-rw-rw-r-- 1 onk onk 88912589 Sep 30 19:18 1696132_hq.mp4
-rw-rw-r-- 1 onk onk 72904313 Sep 30 18:54 18606_hq.mp4
-rw-rw-r-- 1 onk onk 13403523 Sep 30 17:27 19586_hq.mp4
onk@XEON4 ~/STUFF/VIDS/TEST $
onk@XEON4 ~/STUFF/VIDS/TEST $ for i in *.mp4; do echo -n $i " " ; VWxH.sh $i ; done
1467021_hq.mp4 600x480
1684525_hq.mp4 720x480
1696132_hq.mp4 1280x720
18606_hq.mp4 1280x720
19586_hq.mp4 640x480
onk@XEON4 ~/STUFF/VIDS/TEST $
also please try set -xv as it was mentioned, you will see what's happening (and probably post the result and we will explain)
also you can add echo before mv to check the script (and remove echo if that was ok)
onk@XEON4 ~/STUFF/VIDS/TEST $ for i in *.mp4; do echo -n $i " " ; VWxH.sh $i ;cp $i $(VWxH.sh $i)-$i; done
1467021_hq.mp4 600x480
1684525_hq.mp4 720x480
1696132_hq.mp4 1280x720
18606_hq.mp4 1280x720
19586_hq.mp4 640x480
onk@XEON4 ~/STUFF/VIDS/TEST $ for i in *.mp4; do echo -n $i " " ; VWxH.sh $i ;cp $i $i-$(VWxH.sh $i); done
1280x720-1696132_hq.mp4 1280x720
1280x720-18606_hq.mp4 1280x720
1467021_hq.mp4 600x480
1684525_hq.mp4 720x480
1696132_hq.mp4 1280x720
18606_hq.mp4 1280x720
19586_hq.mp4 640x480
600x480-1467021_hq.mp4 600x480
640x480-19586_hq.mp4 640x480
720x480-1684525_hq.mp4 720x480
onk@XEON4 ~/STUFF/VIDS/TEST $
I used cp and not mv, just in case, and it's all good now
The options in the final script will allow for moving or copying, in the same folder or to another folder, and if you precede or follow with the video size.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.