Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting pics off of remote devices, converted and stored on local machine

26 views
Skip to first unread message

fred flintstone

unread,
Jan 18, 2018, 7:49:35 PM1/18/18
to
[x-posted to c.u.shell]
[f-up set to c.u.shell]

On 11/30/2017 03:48 PM, Bit Twister wrote:

>> What do I ls here?
>
> Since you failed to run the indicated commands, continue to waste my
> time and others with noise, I will suggest you ls all of them.

I'm not wasting my time. This script will work soon enough.
>
> Since fred renounces Usenet Netiquette rules. I'll provide any lurkers
> and newbie coders with some tips using fred's script as an example.

in other words, this is bt's script:
>
> Glance at fred's script and this one
> $ cat t
> #!/bin/bash
> #**************************************************
> #* t - test code snippet
> #**************************************************
> export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
> set -u
>
> App=$(basename $0)
> Last_subdir=""
> Log_dir="logs"
> Next_subdir=""
> Out_fn=$HOME/$Log_dir/$App.log
> Pic_dir=""
>
> if [ -z "EDITOR" ] ; then # set default file editor
> EDITOR=gedit
> fi
>
> if [ 1 -eq 0 ] ; then
> echo "basename dollar sign zero is" $App
> echo "path is" $Log_dir
> echo "Munged time is" $_perliname
> echo "out fn is " $Out_fn
> echo "Time is $_perliname " >> $Out_fn
> fi # end if [ 1 -eq 0 ]
>
> date > $Out_fn
>
> cd $HOME/Pictures
> touch 11.cam
^^what is creating a file gonna do for you,
when we need a directory? How many times will you
insist on being wrong?
> Last_subdir=$(ls -1 *.cam | tail -1)

^^this so doesn't work
> set -- $(IFS='.' ; echo $Last_subdir)
> let Next_subdir="$1 + 1"
> Pic_dir="$HOME/Pictures/$Next_subdir.cam"
> mkdir --verbose $Pic_dir
> echo "pic dir is $Pic_dir" >> $Out_fn
> if [ 1 -eq 0 ] ; then
> id >> $Out_fn
> mount >> $Out_fn
> journalctl --since "1 minute ago" >> $_out_fn
> fi # end if [ 1 -eq 0 ]
>
> $EDITOR $Out_fn &
>
> exit 0
> #*********** end t ********************************
>
> Note:
> o PATH statement is provided to allow script to run in cron.
> o consistent variable naming convention.
> o all variables used are sorted and have an initial value.
> o code should use an indention rule.
> o subject matter experts can run mine, because it does not have any
> special external code needed to run like fred's does.
> That give you a much better chance of getting a subject matter
> expert to help you solve your problem, by saving/running it.
> o external environment variable EDITOR can be set by anyone who does
> not have gedit installed, or wants to use their own editor.
>
> Other environment variables are
> export EDITOR=geany # default file editor
> export VISUAL=emacs # default command line editor
> export PAGER=less # default file pager
> export SLRN_EDITOR=emacs # default Usenet slrn client editor
>
> Fred's code does not start with an empty log. Each run just appends
> results to previous run.
>
> Notice I used if [ 1 -eq 0 ] ; then
> to prevent blocks of code from running to help speedup locating a bug
> in other sections of code.
>
> That also reduces what you have to look through if you were to run it using
> bash -x script_fn_here
>
> You need to think about failure modes. Current code does not protect
> against creating new *.cam directories if the last directory is empty.
>
> You also need to think order of execution. In this case there is no
> sense doing the mkdir $Pic_dir if camera is not mounted or camera does
> not have any pictures.
>

I'm glad for the criticism, but the case is that I can't write this
without perl so far, and I have a truly uneasy detente between perl and
bash. What's more, I see parts of this script that I want, so I'll thank
him for it. Finally, I think it would be a relief to us all if I got a
pretty print bash capability, but I have not achieved it yet.

I'm looking at the environment on the device itself. This was accidental
output when I used the wrong terminal to investigate the following commands.

$ export pager=less

[still don't know what his does except require keystrokes]
$ man bash
man: can't change directory to
'/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD
card/DCIM/Camera': No such file or directory
man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N;
/^[[:space:]]*\n[[:space:]]*$/D; }' | (cd
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
&& LESS=-ix8RmPm Manual page bash(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e
(END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page bash(1)
?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help
or q to quit)$ MAN_PN=bash(1) pager)
$ /declare builtin
bash: /declare: No such file or directory
$

--------trying significantly different things

Q1) How do I make an alias of this bash command, such that it is
persistent after rebooting?

$ bash /home/bob/1.scripts/1.zax.sh
basename dollar sign zero is 1.zax.sh
path is /logs
Munged time is 01-16-2018_20-38-42
out fn is /home/bob/logs/01-16-2018_20-38-42.log
Time is 01-16-2018_20-38-42
Gtk-Message: GtkDialog mapped without a transient parent. This is
discouraged.
/home/bob/Desktop/kitty/Room6.JPG /home/bob/Desktop/kitty/Room2.JPG
/home/bob/Desktop/kitty/Room4.JPG /home/bob/Desktop/kitty/Room3.JPG
/home/bob/Desktop/kitty/Room1.JPG /home/bob/Desktop/kitty/Room5.JPG
Orientation: RightTop
exif:Orientation: 6
sh: 1: jpegtran: not found

...

Error : Problem executing specified command
in file '/home/bob/Desktop/kitty/Room5.JPG'
Orientation: RightTop
exif:Orientation: 6
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
today is 2018-01-16
behold your log; stop timer and cat app
-- No entries --
cat: 1.zax.sh: No such file or directory
duration=92

$ cat 1.zax.sh
#!/bin/bash
# reduce-desktop.sh
# modified to make arbitrary path explicit
# and more verbose
# keep a log named by time stamp
set -u
app=${0##*/}

pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log

echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " | tee -a "$out"

TITLE='Reduce JPGs on a path'
VER='0.2'

#Constants

SIZE_LIMIT=640
path_to_pics=/home/bob/Desktop/kitty/
path_to_save=~/Pictures/3.cam/6.resize/
declare -ir SUCCESS=0
declare -ir E_FATAL=1

usage()
{
cat <<EOM
$TITLE v$VER
---------------------------------------------------------------------------
Usage: $(basename $0) [options]

Resize all JPG images on user's desktop to max $SIZE_LIMIT pixel-side
NOTE: requires ImageMagick be installed

-q, --quiet disabled # [ ${QUIET} ] || notify
-h, --help Display this help and exit
-v, --version Output version information and exit

EOM
exit $1
}

# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
echo
usage $1
}

# display script version
version()
{
echo "$app v$VER"
exit $SUCCESS
}

#User confirmation
confirm()
{
MSG="Do you want to autorotate all images on this path $path_to_pics?"
zenity --question --text="$MSG" --title="$TITLE" --display=:0 ||
exit $SUCCESS
}

#User notification
notify()
{
MSG="Images conversion complete"
notify-send "$TITLE" "$MSG" || exit $SUCCESS
}

# Parse command line for options
if (( $# ))
then
case $1 in

-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument"
esac
else
confirm
fi

pics=$(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" -or -iname
"*.jpeg")
echo $pics
for pic in ${pics[@]}
do
identify -verbose $pic | grep Orientation | tee -a "$out"
/home/bob/Downloads/jhead-3.00/jhead -autorot $pic | tee -a "$out"
identify -verbose $pic | grep Orientation | tee -a "$out"
done

pwd | tee -a "$out"
FROM="/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C020%5D/SD
card/DCIM/Camera"


today=$(date +"%Y-%m-%d")
echo "today is $today" | tee -a "$out"
echo "behold your log; stop timer and cat app" | tee -a "$out"
journalctl --since "30 seconds ago" | tee -a "$out"

gedit $out && read -n 1
cat $app | tee -a "$out"
echo "duration=$SECONDS" | tee -a "$out"

exit $SUCCESS

$

Looking for any constructive criticism for this code. Needs a lot of
editing, I know.
--
fred

Bit Twister

unread,
Jan 19, 2018, 4:18:32 AM1/19/18
to
On Thu, 18 Jan 2018 16:49:30 -0800, fred flintstone wrote:
>
> On 11/30/2017 03:48 PM, Bit Twister wrote:
>
>>> What do I ls here?
>>
>> Since you failed to run the indicated commands, continue to waste my
>> time and others with noise, I will suggest you ls all of them.
>
> I'm not wasting my time.

I said nothing about your time and you might notice I could not care
less on how much you continue to waste.

> This script will work soon enough.

Well, so far it have been more than 2 months so I will be surprised if
development speed picks up.



>>
>> cd $HOME/Pictures
>> touch 11.cam
> ^^what is creating a file gonna do for you,
> when we need a directory? How many times will you
> insist on being wrong?

Probably as many times you want to go back in time and bitch about it.

This script was an example on how to post scripting problems not fix
your script. It make no difference if the target was a file or directory.
All that was required was to create the condition to cause the script
failure. Making it a file makes it easier for cleanup when done testing.


>> Last_subdir=$(ls -1 *.cam | tail -1)
>
> ^^this so doesn't work

Very true. Since I cloned your script for this teaching exercise I had
to include it. I suggested you run "man ls" to get correct switch.
Apparently you want to waste everyone's time by refusing to do so.

<snip>

> him for it. Finally, I think it would be a relief to us all if I got a
> pretty print bash capability, but I have not achieved it yet.

And yet again, I suggest installing the package for the geany editor.
Suggest configuring it for 2 space indention. After that you can
highlight the desired selection and hit Ctrl+I it indent a level or
Ctrl+U to un-indent a level.

> I'm looking at the environment on the device itself. This was accidental
> output when I used the wrong terminal to investigate the following commands.
>
> $ export pager=less
>
> [still don't know what his does except require keystrokes]

It allows you to use less's search function to find a term/keyword.



> $ man bash
> man: can't change directory to
> '/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD
> card/DCIM/Camera': No such file or directory
> man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N;
> /^[[:space:]]*\n[[:space:]]*$/D; }' | (cd
> /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
> && LESS=-ix8RmPm Manual page bash(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e
> (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page bash(1)
> ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help
> or q to quit)$ MAN_PN=bash(1) pager)
> $ /declare builtin
> bash: /declare: No such file or directory

As long as you want to bastardize your setup, there is no way any
standard commands subject matter exports provide will work for you.

My suggestion was
$ export pager=less
$ man bash
/declare builtin
which would jump you to that verbiage in the bash man page.
I did not say to execute /declare builtin at the command line.



> Q1) How do I make an alias of this bash command, such that it is
> persistent after rebooting?

You define the alias in the desired login file.
To see which file may be of interest, For the lurkers, try
export pager=less
man bash
/INVOCATION
n
n
n
n
On Ubuntu that should get you to the section of interest.

> sh: 1: jpegtran: not found

Yup. We already had the discussion on how to fix the problem.
If I recall correctly, there was a whole bunch of you were not going
to do a suggestion or two, and a whole bunch of "drama" and "more
drama" comments.

Pretty sure that mentality is not going to help with your
"This script will work soon enough." target.


> cat: 1.zax.sh: No such file or directory

Hehehe, problem seems to becoming logarithmic.
>
> # Parse command line for options
> if (( $# ))
> then
> case $1 in
>
> -h | --help | -\?) usage $SUCCESS;;
> -v | --version) version;;
> *) fatal_error $E_FATAL "Unknown argument"

You may want to consider that a litter extra codding will make it
easier to understand what is wrong.

I would have provide which argument is unknown. Example:
fatal_error $E_FATAL "Unknown argument \"$1\""

pics=$(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" -or -iname
"*.jpeg")
echo $pics
for pic in ${pics[@]}

FYI: you might run into an error like "Argument list too long"
depending on file count/length winding up in the pics string.

suggest using a while loop to avoid the problem.
while read -r Pic_fn; do
identify -verbose $Pic_fn.......
done < <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
-or -iname "*.jpeg")

fred flintstone

unread,
Jan 23, 2018, 2:08:52 PM1/23/18
to
On 01/19/2018 01:18 AM, Bit Twister wrote:
> On Thu, 18 Jan 2018 16:49:30 -0800, fred flintstone wrote:
>>

<snip>
>> This script will work soon enough.
>
> Well, so far it have been more than 2 months so I will be surprised if
> development speed picks up.

Concern yourself less with my "rate of development." It belongs to me.
Mine might increase if you were less persistently wrong, but then who
knows? If my scripts worked perfectly, would I just walk away from them?

These thingies don't seem to evaluate to true + '[' 1 -eq 0 ']'

$ bash -x /home/bob/1.scripts/6.zax.sh
+ export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
+ PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
+ export pager=less
+ pager=less
+ set -u
+ app=6.zax.sh
+ pathto=/logs
++ date +%m-%d-%Y_%H-%M-%S
+ timename=01-22-2018_13-27-18
+ out=/home/bob/logs/01-22-2018_13-27-18.log
+ '[' 1 -eq 0 ']'
+ declare -ir SUCCESS=0
+ declare -ir E_FATAL=1
+ '[' -z EDITOR ']'
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ echo 'mv all in Camera'
mv all in Camera
+ gedit /home/bob/logs/01-22-2018_13-27-18.log
+ read -n 1
+ pwd
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C009%5D/SD card/DCIM/Camera
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ ls -1v
IMG_20180122_132211.jpg
IMG_20180122_132215.jpg
++ perl /home/bob/1.scripts/3.maus
++ tail -1
No name
+ perl_dir=42.cam
+ echo 'perl dir is 42.cam'
perl dir is 42.cam
+ bash_dir=/home/bob/Pictures/42.cam
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ mv 1.required IMG_20180122_132211.jpg IMG_20180122_132215.jpg '.[^.]*'
/home/bob/Pictures/42.cam
mv: cannot stat '.[^.]*': No such file or directory
+ cd /home/bob/Pictures/42.cam
+ pwd
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
/home/bob/Pictures/42.cam
+ ls -1v
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
1.required
IMG_20180122_132211.jpg
IMG_20180122_132215.jpg
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ echo 'behold your log and journal; stop timer and cat app'
behold your log and journal; stop timer and cat app
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ journalctl --since '30 seconds ago'
-- No entries --
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ echo 'dollar zero is /home/bob/1.scripts/6.zax.sh'
dollar zero is /home/bob/1.scripts/6.zax.sh
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ cat /home/bob/1.scripts/6.zax.sh
#!/bin/bash
#
# modified to make arbitrary path explicit
# and more verbose
# keep a log named by time stamp
export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export pager=less
set -u
app=${0##*/}
pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log

if [ 1 -eq 0 ] ; then
echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " > "$out"
fi # end if [ 1 -eq 0 ]

declare -ir SUCCESS=0
declare -ir E_FATAL=1

if [ -z "EDITOR" ] ; then # set default file editor
echo "export from perl didn't work" | tee -a "$out"
EDITOR=gedit
fi

echo "mv all in Camera" | tee -a "$out"
gedit $out && read -n 1

pwd | tee -a "$out"
ls -1v | tee -a "$out"

# get fresh directory from perl to copy images to
perl_dir=$(perl /home/bob/1.scripts/3.maus | tail -1)
echo "perl dir is $perl_dir"
bash_dir=/home/bob/Pictures/$perl_dir
mv {,.[^.]}* $bash_dir | tee -a "$out"
cd $bash_dir
pwd | tee -a "$out"
ls -1v | tee -a "$out"


echo "behold your log and journal; stop timer and cat app" | tee -a "$out"
journalctl --since "30 seconds ago" | tee -a "$out"
echo "dollar zero is $0" | tee -a "$out"
cat $0 | tee -a "$out"
$EDITOR $out &
read -n 1
echo "duration=$SECONDS" | tee -a "$out"
date | tee -a "$out"
exit $SUCCESS

+ read -n 1
/home/bob/1.scripts/6.zax.sh: line 50: EDITOR: unbound variable
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ echo duration=32
duration=32
+ tee -a /home/bob/logs/01-22-2018_13-27-18.log
+ date
Mon Jan 22 13:27:50 PST 2018
+ exit 0
$

>
>
>
>>>
>>> cd $HOME/Pictures
>>> touch 11.cam
>> ^^what is creating a file gonna do for you,
>> when we need a directory? How many times will you
>> insist on being wrong?
>
> Probably as many times you want to go back in time and bitch about it.

Watch your tone.
>
> This script was an example on how to post scripting problems not fix
> your script. It make no difference if the target was a file or directory.
> All that was required was to create the condition to cause the script
> failure. Making it a file makes it easier for cleanup when done testing.
>
>
>>> Last_subdir=$(ls -1 *.cam | tail -1)
>>
>> ^^this so doesn't work
>
> Very true. Since I cloned your script for this teaching exercise I had
> to include it. I suggested you run "man ls" to get correct switch.
> Apparently you want to waste everyone's time by refusing to do so.

Do you have a brain injury? Do you not see the provenance of this
source? Were you writing code like this 2 months ago whilst passing
yourself off as an expert? If not, I'll claim it, because my scripts are
starting to pull together. I used this part to get output from perl : |
tail -1)

We all have a learning with these new technologies. I was particularly
pleased with these scripts we've been writing when I finally went to
purchase a new android. I was able to script the import of images using
these techniques. The millenials who sold me the phone were wide-eyed
when they saw the terminal commands and then program execution: with
images disappearing from the phone. I take a fair amount of images for
clients, so these are ones that I do not want google or facebook or
guccifer to get a hold of. A condition of getting the phone was that it
was going to be able to deal with ubuntu.

>
> <snip>
>
>> him for it. Finally, I think it would be a relief to us all if I got a
>> pretty print bash capability, but I have not achieved it yet.
>
> And yet again, I suggest installing the package for the geany editor.
> Suggest configuring it for 2 space indention. After that you can
> highlight the desired selection and hit Ctrl+I it indent a level or
> Ctrl+U to un-indent a level.

Still trying with this...frustrated.... It doesn't seem to have a
default indentation.
>
>> I'm looking at the environment on the device itself. This was accidental
>> output when I used the wrong terminal to investigate the following commands.
>>
>> $ export pager=less
>>
>> [still don't know what his does except require keystrokes]
>
> It allows you to use less's search function to find a term/keyword.

Important functionality. Thank you for bring this to my attention.
>
>
>
>> $ man bash
>> man: can't change directory to
>> '/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD
>> card/DCIM/Camera': No such file or directory
>> man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N;
>> /^[[:space:]]*\n[[:space:]]*$/D; }' | (cd
>> /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
>> && LESS=-ix8RmPm Manual page bash(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e
>> (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page bash(1)
>> ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help
>> or q to quit)$ MAN_PN=bash(1) pager)
>> $ /declare builtin
>> bash: /declare: No such file or directory
>
> As long as you want to bastardize your setup, there is no way any
> standard commands subject matter exports provide will work for you.
>
> My suggestion was
> $ export pager=less
> $ man bash
> /declare builtin
> which would jump you to that verbiage in the bash man page.
> I did not say to execute /declare builtin at the command line.

I see now. Newer scripts will include
export pager=less
>
>
>
>> Q1) How do I make an alias of this bash command, such that it is
>> persistent after rebooting?
>
> You define the alias in the desired login file.
> To see which file may be of interest, For the lurkers, try
> export pager=less
> man bash
> /INVOCATION
> n
> n
> n
> n

We might have slightly different docs. The way I see it, the source is
going to change in one of three files.

Where should it go if I essentially want to have it all the time?
> On Ubuntu that should get you to the section of interest.
>
>> sh: 1: jpegtran: not found
>
> Yup. We already had the discussion on how to fix the problem.
> If I recall correctly, there was a whole bunch of you were not going
> to do a suggestion or two, and a whole bunch of "drama" and "more
> drama" comments.
>
> Pretty sure that mentality is not going to help with your
> "This script will work soon enough." target.
>
>
>> cat: 1.zax.sh: No such file or directory
>
> Hehehe, problem seems to becoming logarithmic.

Whatevs...it's in a different directory....
>>
>> # Parse command line for options
>> if (( $# ))
>> then
>> case $1 in
>>
>> -h | --help | -\?) usage $SUCCESS;;
>> -v | --version) version;;
>> *) fatal_error $E_FATAL "Unknown argument"
>
> You may want to consider that a litter extra codding will make it
> easier to understand what is wrong.
>
> I would have provide which argument is unknown. Example:
> fatal_error $E_FATAL "Unknown argument \"$1\""

ok
>
> pics=$(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" -or -iname
> "*.jpeg")
> echo $pics
> for pic in ${pics[@]}
>
> FYI: you might run into an error like "Argument list too long"
> depending on file count/length winding up in the pics string.
>
> suggest using a while loop to avoid the problem.
> while read -r Pic_fn; do
> identify -verbose $Pic_fn.......
> done < <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
> -or -iname "*.jpeg")
>

Alright. I see now the same syntax as you mentioned at the beginning of
the the foregoing thread in a.o.l.ubuntu . I didn't understand the
arrows at the bottom util I saw it filled with some meaningful syntax:
< <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
-or -iname "*.jpeg" -or -iname "*.png")
--
fred

Bit Twister

unread,
Jan 23, 2018, 5:05:42 PM1/23/18
to
On Tue, 23 Jan 2018 11:08:43 -0800, fred flintstone wrote:
> On 01/19/2018 01:18 AM, Bit Twister wrote:
>
> These thingies don't seem to evaluate to true + '[' 1 -eq 0 ']'

Very true. Keep in mind the script was a teaching exercise with tips
and tricks.

That if statement was a trick/tip for preventing sections of code from
running when trying to debug a section of code without all the noise
generated within the if statement range.



>
> $ bash -x /home/bob/1.scripts/6.zax.sh
> + export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

Look at, finally back to bash coding 101. Set a known PATH to allow
the script to run in batch/cron and more importantly a known working
environment for executables.


> + export pager=less

As I see it there is no good reason for having that statement in your script.




> + tee -a /home/bob/logs/01-22-2018_13-27-18.log
> + echo 'mv all in Camera'
> mv all in Camera
> + gedit /home/bob/logs/01-22-2018_13-27-18.log
I do not understand why you have a call to edit your log file.

> + read -n 1

Nor a reason for the read if code already paused while in the editor.
Can only guess that you forgot why it was there in the first place.

Originally it was a
echo "connect camera and hit any key to continue" ; read -n 1

> + pwd
> + tee -a /home/bob/logs/01-22-2018_13-27-18.log



> /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C009%5D/SD card/DCIM/Camera
> + tee -a /home/bob/logs/01-22-2018_13-27-18.log
> + ls -1v
> IMG_20180122_132211.jpg
> IMG_20180122_132215.jpg

Now, that looks like some progress has been made. It appears you might
have found a mount point of the camera's contents.


> ++ perl /home/bob/1.scripts/3.maus

Hey, wait a minute there. I thought you said you were not going to
hard code locations to applications in your script.

Had you been listening to what a few people told you all you had to do
as add your script directory to PATH.



> ++ tail -1
> No name
> + perl_dir=42.cam
> + echo 'perl dir is 42.cam'
> perl dir is 42.cam

If that is perl code to generate the next directory for download of
images, that is a pretty big hammer for driving a thumbtack into cork.

> + bash_dir=/home/bob/Pictures/42.cam
> + tee -a /home/bob/logs/01-22-2018_13-27-18.log
> + mv 1.required IMG_20180122_132211.jpg IMG_20180122_132215.jpg '.[^.]*'
> /home/bob/Pictures/42.cam
> mv: cannot stat '.[^.]*': No such file or directory

Looking like you need some more work on the move syntax. Also there
are better commands to use which would do want you want without
throwing an error.

I would have had a function to mount the camera and verify there were
images to move and pop up a message as to what is causing problems.

I would have a function to create the next cam directory just for
readability.

I would not use mv. Reason is, you might not have enough space in the
target directory for all images and maybe room for the last image.
All the images would be gone from the camera without a copy in the cam
directory.

I would copy the files and check return status to verify no failure,
then delete from the camera.

You do that by checking return status variable $? Example:
mv $camera_dir/* $perl_dir/
if [ $? -ne 0 ] ; then
echo "Fatal error: mv $camera_dir/* $perl_dir/" failed"
fi


>
> if [ -z "EDITOR" ] ; then # set default file editor
> echo "export from perl didn't work" | tee -a "$out"
> EDITOR=gedit
> fi

Oh by the way. You want to test an unset variable, it would be better
to use something like
if [ -z ${EDITOR:-""} ] ; then
export EDITOR=gedit
fi


>
> Do you have a brain injury? Do you not see the provenance of this
> source? Were you writing code like this 2 months ago whilst passing
> yourself off as an expert? If not, I'll claim it, because my scripts are
> starting to pull together. I used this part to get output from perl : |
> tail -1)

I wonder how well that perl script works in a clean environment.

Go ahead, try it. Click up a terminal and paste the following:

mkdir -p $HOME/tmp/aa
cd $HOME/tmp/aa
touch 1.cam 11.cam 4.cam 5.cam
ls -al
perl_dir=$(perl /home/bob/1.scripts/3.maus $HOME/tmp/aa | tail -1)
echo "Hopefully perl_dir \"$perl_dir\" is 12.cam and not 6.cam"
rm -r $HOME/tmp/aa


>>>
>>> $ export pager=less
>>>
>>> [still don't know what his does except require keystrokes]
>>
>> It allows you to use less's search function to find a term/keyword.
>
> Important functionality. Thank you for bring this to my attention.
>>
>>
>>> Q1) How do I make an alias of this bash command, such that it is
>>> persistent after rebooting?
>>
>> You define the alias in the desired login file.
>> To see which file may be of interest, For the lurkers, try
>> export pager=less
>> man bash
>> /INVOCATION
>> n
>> n
>> n
>> n
>
> We might have slightly different docs.

Entirely possible. You have not taken my suggestion and placed
information about your OS and Desktop Environment into a ~/.signature
file and configured your Usenet editor to append it to your posts.

For example you could have a gen_sig_file script.
#!/bin/bash
#**************************************************
#* gen_sig_file - generate ~/.signature file
#**************************************************

sig_fn=$HOME/.signature

cat lsb-release > $sig_fn
echo "Desktop $XDG_CURRENT_DESKTOP, kernel $(uname -r) >> $sig_fn
#****************** end gen_sig_file **************

Instructions given for /INVOCATION came from running
$ cat lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"


>> And yet again, I suggest installing the package for the geany editor.
>> Suggest configuring it for 2 space indention. After that you can
>> highlight the desired selection and hit Ctrl+I it indent a level or
>> Ctrl+U to un-indent a level.
>
> Still trying with this...frustrated.... It doesn't seem to have a
> default indentation.

It obviously has a default one. Selections suggest it might even
figure out which one to use. I prefer 2 spaces. Bash coding
suggestions is to not use tabs. Very handy rule to follow. Makes it
real easy to cut code from script and paste into a terminal to verify/see
what happens.

For indention, click Edit, Preferences, Editor, Indention, set Width 2,
and click Spaces. While there you might want to click Competitions tab,
and enable all the Auto-close quotes and Brackets.

fred flintstone

unread,
Jan 25, 2018, 8:14:45 PM1/25/18
to
On 01/19/2018 01:18 AM, Bit Twister wrote:
Got that in there now:

$ ./3.reduce-desktop.sh -p
basename dollar sign zero is 3.reduce-desktop.sh
path is /logs
Munged time is 01-25-2018_17-02-37
out fn is /home/bob/logs/01-25-2018_17-02-37.log
Time is 01-25-2018_17-02-37
Error #1: Unknown argument "-p"

./3.reduce-desktop.sh: line 42: QUIET: unbound variable
$

>
> pics=$(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" -or -iname
> "*.jpeg")
> echo $pics
> for pic in ${pics[@]}
>
> FYI: you might run into an error like "Argument list too long"
> depending on file count/length winding up in the pics string.
>
> suggest using a while loop to avoid the problem.
> while read -r Pic_fn; do
> identify -verbose $Pic_fn.......
> done < <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
> -or -iname "*.jpeg")
>

Alright, I'm really pleased with where I'm leaving it for the day. I got
one loop written for processing the files along these lines, and I tried
to extend it to process the directories in pictures. What's more, I got
the generalized EDITOR bit going.
Time is 01-25-2018_17-01-37
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
Orientation: TopLeft
exif:Orientation: 1
exif:thumbnail:Orientation: 1
10.cam
11.cam
12.cam
13.cam
14.cam
Screenshot from 2018-01-22 08-51-37.png
Screenshot from 2018-01-22 09-43-59.png
Screenshot from 2018-01-22 17-02-59.png
Screenshot from 2018-01-25 11-37-53.png
Webcam
today is 2018-01-25
behold your log; stop timer and cat app
-- No entries --
#!/bin/bash
# reduce-desktop.sh
# modified
# and more verbose
# keep a log named by time stamp
set -u
app=${0##*/}

pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log

echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " | tee -a "$out"

TITLE='Reduce JPGs on a path'
VER='0.2'

#Constants

SIZE_LIMIT=640
path_to_pics=/home/bob/Pictures/43.cam/resize
path_to_save=~/Pictures/3.cam/6.resize/
declare -ir SUCCESS=0
declare -ir E_FATAL=1

trap_err()
{
echo " $(caller) errexit on line $1 $BASH_COMMAND exit status=$2" >&2
}
trap 'trap_err ${LINENO} $?' ERR

if [ -z ${EDITOR:-""} ] ; then
export EDITOR=gedit
fi

usage()
{
cat <<EOM
$TITLE v$VER
---------------------------------------------------------------------------
Usage: $(basename $0) [options]

Resize all JPG images on user's desktop to max $SIZE_LIMIT pixel-side
NOTE: requires ImageMagick be installed

-q, --quiet disabled # [ ${QUIET} ] || notify
-h, --help Display this help and exit
-v, --version Output version information and exit

EOM
exit $1
}

# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
echo
usage $1
}

# display script version
version()
{
echo "$app v$VER"
exit $SUCCESS
}

#User confirmation
confirm()
{
MSG="Do you want to do something with all images on this path
$path_to_pics?"
zenity --question --text="$MSG" --title="$TITLE" --display=:0 ||
exit $SUCCESS
}

#User notification
notify()
{
MSG="Images conversion complete"
notify-send "$TITLE" "$MSG" || exit $SUCCESS
}

# Parse command line for options
if (( $# ))
then
case $1 in

-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument \"$1\""
esac
else
confirm
fi


while read -r Pic_fn; do
identify -verbose $Pic_fn | grep Orientation | tee -a "$out"
done < <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
-or -iname "*.jpeg" -or -iname "*.png")

# get list of dirs in Pictures

hamster=$HOME/Pictures/
ls -1 $hamster | head -5 | tee -a "$out"
ls -1 $hamster | tail -5 | tee -a "$out"

while read -r dir_fn; do

echo "dir is $dir_fn" | tee -a "$out"

done < <(find $hamster -maxdepth 1 -regex "[0-9.cam]"-type d )


today=$(date +"%Y-%m-%d")
echo "today is $today" | tee -a "$out"
echo "behold your log; stop timer and cat app" | tee -a "$out"
journalctl --since "30 seconds ago" | tee -a "$out"

gedit $out & #this works great
touch 1.gedit.txt
echo "hello gedit" >1.gedit.txt
$EDITOR 1.gedit.txt &
cat $app | tee -a "$out"
echo "duration=$SECONDS" | tee -a "$out"

exit $SUCCESS

duration=15

My syntax on the find statement seems to be falling short. I only want
directories of the form number dot cam. Gotta leave my cave, ahhh!

Fishing for tips,
--
fred

Bit Twister

unread,
Jan 26, 2018, 6:33:28 AM1/26/18
to
On Thu, 25 Jan 2018 17:14:37 -0800, fred flintstone wrote:

> #!/bin/bash

I have mentioned it a few times. If you want to make it easy for
subject matter experts to help you with your code, you need to make it
so they can run your code with the least amount modifications and I
can recommend getting into the habit of not using ~. Example:

before
path_to_pics=/home/bob/Pictures/43.cam/resize
path_to_save=~/Pictures/3.cam/6.resize/
after
path_to_pics=$HOME/Pictures/43.cam/resize
path_to_save=$HOME/Pictures/3.cam/6.resize/


Those path_to_* values looks incorrect to me.

Since you have failed on hints, suggestions, actual code examples,
I'll suggest something like
Cam_Dir=""
Cam_Dir_Loc=$HOME/Pictures
path_to_pics-""
path_to_save=""

function set_next_cam_dir ()
{
cd $Cam_Dir_Loc
if [ $? -ne 0 ] ; then
fatal_error $E_FATAL "cd $Cam_Dir_Loc failed"
fi

set -- $(IFS='.' ; echo $(ls -1dv [0-9].cam | tail -1))
let n="$1 + 1"
Cam_dir="$n.cam"
path_to_pics=$Cam_Dir_Loc/$Cam_Dir
path_to_save=$Cam_Dir_Loc/$Cam_Dir/resize
cd $OLDPWD
} # end function set_next_cam_dir




>
> if [ -z ${EDITOR:-""} ] ; then
> export EDITOR=gedit
> fi

If you have moved to using geany as your editor, I can recommend
getting into
Edit-> Preferences-> Editor click the Display tab
there you might want to set
Show indention guides
Show white space
Show line numbers
Show markers margin
Stop scrolling at last line

Under Long line marker
set Enabled

That will give you an indicator to allow you to decide to mange lines
longer than 72 characters.

Kind of helps if you post to Usenet and paging or using cat -n in a
normal 80 character wide terminal.

Click Apply, ok

Now you should be able to see indention guides which can help when you
when you do not have correct end of statement keyword.

In other words, I suggest the statement should look like

if [ -z ${EDITOR:-""} ] ; then
export EDITOR=gedit
fi





> $TITLE v$VER
> ---------------------------------------------------------------------------
> Usage: $(basename $0) [options]

Why use basename when you already have it in $app


> # Parse command line for options
> if (( $# ))
> then

That logic/expression is not correct. If statement rules are
If result of expression is 0
then
true code here
else
false code here
fi

Personally, I will do the extra typing to make if obvious to whoever
has to read my code. I also makes easy for me to speed read my code.

if [ $# -ne 0 ] ; then
case $1 in
-h | --help | -\?) usage $SUCCESS ;;
-v | --version) version ;;
*) fatal_error $E_FATAL "Unknown argument \"$1\""
esac

You are missing ;; at end of the *) line.

Looking at all your code, there is no reason to have the
else
confirm
fi

Remove the else and put the confirm after fi.


> while read -r Pic_fn; do
> identify -verbose $Pic_fn | grep Orientation | tee -a "$out"
> done < <(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" \
> -or -iname "*.jpeg" -or -iname "*.png")

again, line up end of statement keyword.


> while read -r dir_fn; do
>
> echo "dir is $dir_fn" | tee -a "$out"
>
> done < <(find $hamster -maxdepth 1 -regex "[0-9.cam]"-type d )

again, line up end of statement keyword AND use indentation. Example

while read -r dir_fn; do
echo "dir is $dir_fn" | tee -a "$out"
done < <(find $hamster -maxdepth 1 -regex "[0-9.cam]"-type d )

If you do not want to spend time making it easy for subject matter
experts to read your code, you run the risk of subject matter experts
not bothering to continue reading your post.

> gedit $out & #this works great
> touch 1.gedit.txt

touch command is waste of cpu and storage space because

> echo "hello gedit" >1.gedit.txt

Creates the file.


> $EDITOR 1.gedit.txt &

For what you did I suggest the code should be
echo "hello $EDITOR" > 1.$EDITOR.txt
$EDITOR 1.$EDITOR.txt &


Bit Twister

unread,
Jan 26, 2018, 7:51:33 AM1/26/18
to
On Fri, 26 Jan 2018 11:33:23 -0000 (UTC), Bit Twister wrote:
> On Thu, 25 Jan 2018 17:14:37 -0800, fred flintstone wrote:
>
>> # Parse command line for options
>> if (( $# ))


FYI: If using geany you can do something like
grep -l 'if (( $#' * | awk '{print "geany " $1 " &" }' > a
. ./a

That should bring up geany with all files with the "if (( $# ))" string.
Hit the global replace key, enter
from: if (( $# ))
to: if [ $# -ne 0 ]
and click the In Session button. That will modify all files.
Do the same thing again
from: \"$1\""
to: \"$1\"" ;;

fred flintstone

unread,
Jan 30, 2018, 6:10:15 PM1/30/18
to
On 01/26/2018 03:33 AM, Bit Twister wrote:

> If you have moved to using geany as your editor, I can recommend
> getting into
> Edit-> Preferences-> Editor click the Display tab
> there you might want to set
> Show indention guides
> Show white space
> Show line numbers
> Show markers margin
> Stop scrolling at last line
>
> Under Long line marker
> set Enabled
>
> That will give you an indicator to allow you to decide to mange lines
> longer than 72 characters.
>
> Kind of helps if you post to Usenet and paging or using cat -n in a
> normal 80 character wide terminal.
>
> Click Apply, ok
>
> Now you should be able to see indention guides which can help when you
> when you do not have correct end of statement keyword.
>
Getting geany to work on either *nix partition is the central battle now.

On mint, I'm trying to script it like any other start-up activity. I
know this code is ugly, but the worst of it does have the virtue of
being commented out and then switched off as the if condition fails.

I'm perplexed that I can neither unzip nor untar a .zip file.

fred@fred-ThinkPad-SL510 ~/perl-master $ bash 1.unzip.bash geany
basename dollar sign zero is 1.unzip.bash
path is /logs
Munged time is 01-30-2018_14-05-29
out fn is /home/fred/logs/xx__01-30-2018_14-05-29.log
geany-master.zip
mkdir: cannot create directory ‘/home/fred/geany’: File exists
word is geany
file is geany-master.zip
gzip: stdin has more than one entry--rest ignored
tar: Child returned status 2
tar: Error is not recoverable: exiting now
/home/fred/geany
ls: cannot access *geany*: No such file or directory
fred@fred-ThinkPad-SL510 ~/perl-master $ cat 1.unzip.bash
#!/bin/bash
#
# keep a log named by time stamp
#
export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
set -u
app=${0##*/}
pathto=/logs
master="master"
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/xx__$timename.log

if [ -z ${EDITOR:-""} ] ; then
export EDITOR=gedit
fi

if [ 1 -eq 1 ] ; then
echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " > "$out"
fi # end if [ 1 -eq 0 ]

declare -ir SUCCESS=0
declare -ir E_FATAL=1

if [ 1 -eq 0 ] ; then

# 314 sudo apt-get install mtp-tools
# 315 cat 1.mtp.txt | less
# 316 mtp-detect >1.mtp.txt
# 317 mtp-detect >1.mtp.txt
# 318 1001
# 319 cat 1.mtp.txt | less
# 320 type perl
cat /etc/lsb-release | tee -a "$out"
# 322 apt-get search perl | grep -i ^perl #no output


338 sudo mount /dev/sdb1 /mnt
cd /mnt

cd backupjune16/dir/pages2/hunt/
mount >1.mnt.mint.txt | tee -a "$out"
mtp-detect >1.mtp.mint.txt | tee -a "$out"

env | sort | tee -a "$out"
ls -1v | tee -a "$out"
fi # end if [ 1 -eq 0 ]


# unzip
if [ 1 -eq 1 ] ; then
word=$1
cd $HOME/Downloads/
ls *$word*.zip | head -5 | tee -a "$out"


#big hammer
mkdir $HOME/$word
echo "word is $word" | tee -a "$out"
FILE=$(ls *$word*.zip | head -1)
echo "file is $FILE" | tee -a "$out"
#unzip -d $(ls *$word*.zip | head -1) $HOME/$word/
tar -xvzf $HOME/Downloads/$FILE -C $HOME/$word
cd $HOME/$word/
pwd | tee -a "$out"
ls -lh *$word* | head -5 | tee -a "$out"
fi # end if [ 1 -eq 0 ]

$EDITOR $out &
exit $SUCCESS
fred@fred-ThinkPad-SL510 ~/perl-master $

I tried a million things here, finalizing on having the absolute path
for the file in the tar command, which sounds wrong for a zip file
anyways, but I had the same trouble with unzip.

This shows screenshots of geany on the other partition, where I do not
have the option to save a file. I had the pull down file menu shown as I
clicked print-screen, but it did not show up with the fuzzed out "save"
option. I'm convinced that I installed geany wrong from the git-go over
there:

http://merrillpjensen.com/pages/1.geany2.html

Fishing for tips, tricks, and links, never above reading....
--
fred


fred flintstone

unread,
Feb 7, 2018, 1:36:08 PM2/7/18
to
geany 1.bounce.sh &
geany 1.crumpets.sh &
geany 1.rabbit &
geany 1.rabbit.sh &
geany 1.reduce-desktop.sh &
geany 1.repos.sh &
geany 1.wrapper.sh &
geany 1.zax.sh &
geany 2.rabbit.sh &
geany 2.reduce-desktop.sh &
geany 2.repos.sh &
geany 2.zax.sh &
geany 3.rabbit.sh &
geany 3.reduce-desktop.sh &
geany 3.repos.sh &
geany 3.zax.sh &
geany 4.zax.sh &
#!/bin/bash
#
#
#
# keep a log named by time stamp
set -u
app=$(basename $0)
mkdir $HOME/logs
pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log

echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " | tee -a "$out"

TITLE='Builder'
VER='.1'

#Constants

declare -ir SUCCESS=0
declare -ir E_FATAL=1

trap_err()
{
echo " $(caller) errexit on line $1 $BASH_COMMAND exit status=$2" >&2
}
trap 'trap_err ${LINENO} $?' ERR

if [ -z ${EDITOR:-""} ] ; then
export EDITOR=$(which geany)
fi

usage()
{
cat <<EOM
$TITLE v$VER
---------------------------------------------------------------------------
Usage: $(basename $0) [options]



-q, --quiet disabled # [ ${QUIET} ] || notify
-h, --help Display this help and exit
-v, --version Output version information and exit

EOM
exit $1
}

# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
echo
usage $1
}

# display script version
version()
{
echo "$app v$VER"
exit $SUCCESS
}

#User confirmation
confirm()
{
MSG="Do you want to do something?"
zenity --question --text="$MSG" --title="$TITLE" --display=:0 ||
exit $SUCCESS
}

#User notification
notify()
{
MSG="processing complete"
notify-send "$TITLE" "$MSG" || exit $SUCCESS
}

# Parse command line for options
if (( $# ))
then
case $1 in

-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument \"$1\"";;
esac
else
confirm
fi
#####
#./1.lemuel.sh laman
grep -l 'if (( $#' * | awk '{print "geany " $1 " &" }' > "$out"


$EDITOR $app &
cat $app | tee -a "$out"
echo "duration=$SECONDS" | tee -a "$out"
gedit $out &
exit $SUCCESS

duration=3

Can you elaborate on how I was to make that change in one fell swoop?
Otherwise, I just hope to eliminate invalid syntax by outpacing it with
newer scripts. I certainly like having this grep example to search for
such specific syntax. Shows how a person needs to be able to function
inside the editor as well as outside.

I can't get indenting to work yet, but I have some functionality with
geany. What I like about this is that it calls it from the command line.
Obviates the hunt and peck with gui events.
--
fred

Bit Twister

unread,
Feb 7, 2018, 3:28:43 PM2/7/18
to
On Wed, 7 Feb 2018 10:36:01 -0800, fred flintstone wrote:
> On 01/26/2018 04:51 AM, Bit Twister wrote:
>> On Fri, 26 Jan 2018 11:33:23 -0000 (UTC), Bit Twister wrote:
>>> On Thu, 25 Jan 2018 17:14:37 -0800, fred flintstone wrote:
>>>
>>>> # Parse command line for options
>>>> if (( $# ))
>>
>>
>> FYI: If using geany you can do something like
>> grep -l 'if (( $#' * | awk '{print "geany " $1 " &" }' > a
>> . ./a
>>
>> That should bring up geany with all files with the "if (( $# ))" string.
>> Hit the global replace key, enter
>> from: if (( $# ))
>> to: if [ $# -ne 0 ]
>> and click the In Session button. That will modify all files.
>> Do the same thing again
>> from: \"$1\""
>> to: \"$1\"" ;;
>>
>
> geany 1.bounce.sh &
> geany 1.crumpets.sh &
<snip>
> geany 3.zax.sh &
> geany 4.zax.sh &

>
> Can you elaborate on how I was to make that change in one fell swoop?

Well, offhand I do not see how I could be more elaborate except for
telling you what the global replace key to use. Reason I left that out
is because I changed it to a Ctrl+r quite awhile back and no longer
remember what it was. Hang on while I go boot your distribution,
install geany, and look it up for you . . . . . . . . . .
Ha ha, it is h, so try ctrl+h


Your above results indicated had you executed the command ". ./a"
I would have expected you to see all those files opened in one geany
window. After you hit the global replace key (ctrl+h), changed the from/to
fields, one of the button selections would be In session. As soon as
you click it, geany would modify all the files, and their name would
change to red indicating changes have been made to those files.
All would be left is ctrl+s ctrl+w on each to save/close it, or in
your case, GUESSING clicking exit, and click save on each one.


> Otherwise, I just hope to eliminate invalid syntax by outpacing it with
> newer scripts. I certainly like having this grep example to search for
> such specific syntax. Shows how a person needs to be able to function
> inside the editor as well as outside.

It also points out that coding consistency can help with productivity
in the case of wholesale changes. For example hostname --alias is deprecated
so I had to change 30 files to hostname --short.


> I can't get indenting to work yet,

I honestly do not know what your problem is. Set it spaces only,
indent 2 and it should indent whenever it knows to do so, or if you
select/highlight some code and hit ctrl+i a few times or ctrl+u to
un-indent.

I just now tested it on your distribution. Entered
geany a(Enter key)
#!/bin/bash
(hit ctrl+s)
(tab key)if [ 1 -ne 0 ] ; then
(tab key)asdf
yyert
sdfgfg
(del key) (del key)
fi


> What I like about this is that it calls it from the command line.
> Obviates the hunt and peck with gui events.

Well, you can learn to make the computer work for you, or you can let
the computer make you work for it.

If you became halfway proficient with your shell, it would not be that
hard to have a while loop, using awk or sed to make these kinds of
changes without you having to do the changes interactively.

You could also use the same methodology to change that
from app=$(basename $0)
to app=${0##*/}
0 new messages