LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BASH Script - What am I doing wrong in this test? - BASH Script (https://www.linuxquestions.org/questions/programming-9/bash-script-what-am-i-doing-wrong-in-this-test-bash-script-4175603408/)

BW-userx 04-07-2017 02:09 PM

BASH Script - What am I doing wrong in this test? - BASH Script
 
example page I had to go and check it to make sure it was not a me mistake.
http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html

Code:

if [ -f /var/log/messages ]
  then
    echo "/var/log/messages exists."
fi


just check to see if file is present if true returns 0 then acts on it. my code.

Code:

script_dir="~/scripts"
Code:

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"
reslults set -x
Code:

next line is to lame flac file
+ [[ flac == \f\l\a\c ]]
+ flac -cd '/media/data/Deluge_Done/1979 - Public Image Ltd. - Metal Box [Virgin Vinyl 24-96 FLAC][2009][Kel Bazar]/01 - Albatross.flac'
+ lame -b 320 - '01 - Albatross.mp3'
flac 1.3.1, Copyright (C) 2000-2009  Josh Coalson, 2011-2014  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.
01 - Albatross.flac: done       
LAME 3.99.5 64bits (http://lame.sf.net)
Resampling:  input 96 kHz  output 48 kHz
Using polyphase lowpass filter, transition band: 20323 Hz - 20903 Hz
Encoding <stdin> to 01 - Albatross.mp3
Encoding as 48 kHz j-stereo MPEG-1 Layer III (4.8x) 320 kbps qval=3

now comes the check to insure that a file was re-sampled
Code:


+ [[ -f ~/scripts/01 - Albatross.mp3 ]]

#
#  It tested true but did not set the variable The next line proves it.
#
+ printf '\n\n\ resampledFileLoc --> \n\n\n\n'
\ resampledFileLoc -->

#
# nothing was inside of it
#
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]

I even changed it to

Code:


if [[ -f "${script_dir}"/"${NewFile}" ]] ; then
resampledFileLoc="${script_dir}"/"${NewFile}"
fi

and I still get the same results.

entire partial code block ( did you see what I did? I said entire partial code block that contradicts itself ;) you didn't catch that did you? )
Code:


#Set newFile name for converted flac to mp3
[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

#check for extension type

 printf "next line is to lame flac file\n\n\n\n\n"
 
[[ "${ext}" == 'flac' ]] && flac -cd "$FILENAME" | lame -b 320 - "$NewFile"

# check to be sure file was created

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"


printf "\n\n\ resampledFileLoc --> $resampledFileLoc\n\n\n\n"

#check to be sure it is there again and check to be sure directories to move it to are there before moving 
[[ ! -z "resampledFileLoc" && -d  "${ArtistAlbum}" ]] && ( mv -v "resampledFileLoc" "${ArtistAlbum}" ; unset ArtistAlbum )

what am I doing wrong now?

NevemTeve 04-07-2017 02:23 PM

Please create a complete script that shows the problem and is minimal (everything in it is essential to produce the problem),

BW-userx 04-07-2017 02:29 PM

Quote:

Originally Posted by NevemTeve (Post 5693990)
Please create a complete script that shows the problem and is minimal (everything in it is essential to produce the problem),

now I got a copy right it Just in case .. J/k

Code:


#!/bin/bash

#Take meta data and use it to rename mp3 files taken off iPhone
# then make directories by band name and album.
#Then copy it into same said directories
#accordingly
#Apr. 06, 2017

working_dir="/media/data/Deluge_Done"
copy_to="/media/data/Sorted_iPhone-Music"
move_to="/media/data/LostTitle_iPhone_Music"
script_dir="~/scripts"


set -x

#find "$working_dir" -type f -name "*.mp3" | while read FILENAME

while read FILENAME
do

#unset ARTIST
#unset TITLE
#unset ALBUM
#unset GENRE
#unset NewFile

#get path - file name - extension

                f=$FILENAME
                path=${f%/*}
                xfile=${f##*/}
                title=${xfile%.*}
                ext=${xfile##*.}
               
        printf "\n\n\n\ this is extension -> $ext\n\n\n\n"
#get needed metadata tag info
ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool  -Title  "$FILENAME" -p '$Title'`"
ALBUM="`exiftool  -Album  "$FILENAME" -p '$Album'`"
GENRE="`exiftool  -Genre  "$FILENAME" -p '$Genre'`"

# create parent directory

mkdir -vp "${move_to}"

# create directories needed for file to be placed in

[[ ! -z "${ARTIST}" ]] && ( artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}" )
 
[[ ! -z "${ALBUM}" && ! -z "${ARTIST}" ]] && ( ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM" ; mkdir -pv "${ArtistAlbum}" )


#Set newFile name for converted flac to mp3
[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

#check for extension type

 printf "next line is to lame flac file\n\n\n\n\n"
 
[[ "${ext}" == 'flac' ]] && flac -cd "$FILENAME" | lame -b 320 - "$NewFile"

# check to be sure file was created

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"


printf "\n\n\ resampledFileLoc --> $resampledFileLoc\n\n\n\n"

#check to be sure it is there again and check to be sure directories to move it to are there before moving 
[[ ! -z "resampledFileLoc" && -d  "${ArtistAlbum}" ]] && ( mv -v "resampledFileLoc" "${ArtistAlbum}" ; unset ArtistAlbum )


[[ ! -z "resampledFileLoc" && -d "${artist}" ]] && ( mv -v "resampledFileLoc" "${artist}" ; unset resampledFIleLoc )


#[[ ! -z "$ARTIST" ]] && mkdir -vp "$artist"

#[[ ! -z "$ARTIST" && ! -z "$ALBUM" ]] && mkdir -vp "$ArtistAlbum"


[[ "${ext}" == 'mp3' && -d "${ArtistAlbum}" ]] && cp -v "$FILENAME"  "${ArtistAlbum}"

[[ "${ext}" == 'mp3' && ! -d "${ArtistAlbum}" && -d "${artist}" ]] && cp -v "${FILENAME}" "${artist}"



unset ARTIST
unset TITLE
unset ALBUM
unset GENRE
unset NewFile

done < <(find "$working_dir" -type f  \( -name '*.mp3' -o -name '*.flac' \))

it is no longer for what the description says its for. I just kept some of it, and rewrote the body of it to re-sample flac and copy mp3s from somewhere else into a different file structure

NevemTeve 04-07-2017 02:37 PM

Are you sure that every line of this scripts is necessary to show the problem?

BW-userx 04-07-2017 02:57 PM

yes because of this ;;;;;


if you change it to suit your system then run it, using test data one flac and one mp3

you'll see that none of the variables are being set or loses its value when a test returns true.

but look at it.

Code:

+ ALBUM='Marquee Moon '
++ exiftool -Genre '/media/data/Deluge_Done/(1977) Marquee Moon/03. Television - Friction.samantha.mp3' -p '$Genre'
+ GENRE=Post-Punk
+ mkdir -vp /media/data/LostTitle_iPhone_Music

## the varitable has a value so it is true, then it sets artist to equal the path to create
## the directory as told, then loses its value so it cannot be used later on with an mp3


+ [[ -n Television ]]
+ artist=/media/data/Sorted_iPhone-Music/Television
+ mkdir -pv /media/data/Sorted_iPhone-Music/Television


#
#here the value is no longer in the variable
#


+ printf '\n artist 1 --> \n\n'
 artist 1 -->

+ [[ -n Marquee Moon  ]]
+ [[ -n Television ]]
+ ArtistAlbum='/media/data/Sorted_iPhone-Music/Television/Marquee Moon '
+ mkdir -pv '/media/data/Sorted_iPhone-Music/Television/Marquee Moon '


#then its value inside of Variable is lost

+ printf ' \n\n ArtistAlbum 1 -->  \n\n'

the directories are being created

Code:

/media/data/Sorted_iPhone-Music/Television/Marquee Moon
copy paste off file manager to show its existence.

astrogeek 04-07-2017 03:19 PM

I have not been able to make sense of the original question or the following test case.

Please show us this and exactly this so that we can understand it and repeat it...

* Some variable with a value, echo that value
* Your test of that variable from your code which you say is affecting the variable value
* That same variable value after the test at which point you say has lost its value

michaelk 04-07-2017 03:43 PM

Code:

script_dir="~/scripts"
With quotes the ~ is not being expanded to /home/username.

BW-userx 04-07-2017 03:46 PM

Quote:

Originally Posted by astrogeek (Post 5694008)
I have not been able to make sense of the original question or the following test case.

Please show us this and exactly this so that we can understand it and repeat it...

* Some variable with a value, echo that value
* Your test of that variable from your code which you say is affecting the variable value
* That same variable value after the test at which point you say has lost its value

that is all within there already..just got a look for it, I even put it in bold but let me repeat myself just for you....

broke down as this is doing this with every test then set the value then it is lost through out the entire script.

without set -x using printf - results are this
Code:


userx@slackwhere⚡~/scripts $./metadata-restore-mp3s
\ this is extension -> mp3
 artist 1 -->
 
 ArtistAlbum 1 --> 
next line is to lame flac file
\ resampledFileLoc -->

the lines of code are this

Code:

                f=$FILENAME
                path=${f%/*}
                xfile=${f##*/}
                title=${xfile%.*}
                ext=${xfile##*.}
               
        printf "\n\n\n\ this is extension -> $ext\n\n\n\n"
#get needed metadata tag info
ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool  -Title  "$FILENAME" -p '$Title'`"
ALBUM="`exiftool  -Album  "$FILENAME" -p '$Album'`"
GENRE="`exiftool  -Genre  "$FILENAME" -p '$Genre'`"

# create parent directory

mkdir -vp "${move_to}"

# create directories needed for file to be placed in

[[ -n "${ARTIST}" ]] && ( artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}" )

printf "\n artist 1 --> $artist\n\n"
 
[[ -n "${ALBUM}" && -n "${ARTIST}" ]] && ( ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM" ; mkdir -pv "${ArtistAlbum}" )

printf " \n\n ArtistAlbum 1 -->  $ArtistAlbum\n\n"


#Set newFile name for converted flac to mp3
[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

#check for extension type

 printf "next line is to lame flac file\n\n\n\n\n"
 
[[ "${ext}" == 'flac' ]] && flac -cd "$FILENAME" | lame -b 320 - "$NewFile"

# check to be sure file was created

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"

if [[ -f "${script_dir}"/"${NewFile}" ]] ; then
{

id3v2 -A "$ALBUM" "$resampledFileLoc"
id3v2 -a "$ARTIST" "$resampledFileLoc"
id3v2 -t "$TITLE" "$resampledFileLoc"
id3v2 -g "$GENRE" "$resampledFileLoc"

}
fi


#if metadata is empty use file and directories for tags on re-sampled flac files

 file=$FILENAME
 file=${c##*/}
 album=${c#*"${c%/*/"$file"}"/}
 band=${c#*"${c%/*/"$album"}"/}
 band=${band%%/*}
 album=${album%%/*}

if [[ ! -n "$ALBUM" ]] ; then
        #  folder name of that band album added to orginal file.mp3 as tag info
        id3v2 -A "$album" "${FILENAME}"
  # echo  id3v2 -l ${file} " that is new tag added to "
  fi
 

if [[ ! -n "$ARTIST" ]] ; then
        # folder name of artist/band name added to original file.mp3 as tag info
        id3v2 -a "$band" "${FILENAME}"
    echo $band " added band to file "
        fi
       
        if [[ ! -n "$TITLE" ]] ; then
  # if no song title in tag info then add original file name as tag title info
        id3v2 -t "$pref" "${FILENAME}"
        echo
       
fi


printf "\n\n\ resampledFileLoc --> $resampledFileLoc\n\n\n\n"

none of that is getting processed properly.

set -x out put nd what I got a look at to show me that it is not working.


Code:



userx@slackwhere⚡~/scripts $./metadata-restore-mp3s
+ find /media/data/Deluge_Done -type f '(' -name '*.mp3' -o -name '*.flac' ')'
+ read FILENAME
+ f='/media/data/Deluge_Done/(1977) Marquee Moon/01. Television - See No Evil.samantha.mp3'
+ path='/media/data/Deluge_Done/(1977) Marquee Moon'
+ xfile='01. Television - See No Evil.samantha.mp3'
+ title='01. Television - See No Evil.samantha'
+ ext=mp3
+ printf '\n\n\n\ this is extension -> mp3\n\n\n\n'
\ this is extension -> mp3
++ exiftool -Artist '/media/data/Deluge_Done/(1977) Marquee Moon/01. Television - See No Evil.samantha.mp3' -p '$Artist'
+ ARTIST=Television
++ exiftool -Title '/media/data/Deluge_Done/(1977) Marquee Moon/01. Television - See No Evil.samantha.mp3' -p '$Title'
+ TITLE='See No Evil'
++ exiftool -Album '/media/data/Deluge_Done/(1977) Marquee Moon/01. Television - See No Evil.samantha.mp3' -p '$Album'
+ ALBUM='Marquee Moon '
++ exiftool -Genre '/media/data/Deluge_Done/(1977) Marquee Moon/01. Television - See No Evil.samantha.mp3' -p '$Genre'
+ GENRE=Post-Punk
+ mkdir -vp /media/data/LostTitle_iPhone_Music
+ [[ -n Television ]]
+ artist=/media/data/Sorted_iPhone-Music/Television
+ mkdir -pv /media/data/Sorted_iPhone-Music/Television
+ printf '\n artist 1 --> \n\n'
 artist 1 -->
+ [[ -n Marquee Moon  ]]
+ [[ -n Television ]]
+ ArtistAlbum='/media/data/Sorted_iPhone-Music/Television/Marquee Moon '
+ mkdir -pv '/media/data/Sorted_iPhone-Music/Television/Marquee Moon '
+ printf ' \n\n ArtistAlbum 1 -->  \n\n'
 
 ArtistAlbum 1 --> 
+ [[ mp3 == \f\l\a\c ]]
+ printf 'next line is to lame flac file\n\n\n\n\n'
next line is to lame flac file

using the same code

I do not know what else I can show you that is not already there


I can decipher it

lets me see if I can break it down some more... the whole script is doing this.

Code:


#gets value to put in variable or tested
script_dir="~/scripts"
title=${xfile%.*}
ext=${xfile##*.}

[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

# ext test returns true the Variables is then set by values see above.

next test again looking for ext = flac if yes re-sample change to mp3
[[ "${ext}" == 'flac' ]] && flac -cd "$FILENAME" | lame -b 320 - "$NewFile"

# to be sure that a flac had beed created test to see if that file is in the script dir where it
# gets created. it true then set the path/FileName to the variable for further processing

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"

#I've changed my non working code so let me put it back as the changes did not effect it into working.

# now that the entire path to and newfile name have been put into a variable  it still needs to be checked
#due to this being procedure and working with two different extensions at once flac and mp3.
# check to see if file is true and that a directory have been created to put it in first before trying to move it.

[[ ! -z "$resampledFileLoc" && -d "${artist}" ]] && ( mv -v "$resampledFileLoc" "${artist}" ; unset resampledFIleLoc )

#by the time it gets to that line of code this Var resampledFileLoc is empty or it never gets filled. and the check on the dir for true #by the process by which it was created this variable artist too is empty so it return null. that value was lost right after it created #the directory.

+ [[ -n Marquee Moon  ]]
+ [[ -n Television ]]
+ ArtistAlbum='/media/data/Sorted_iPhone-Music/Television/Marquee Moon '
+ mkdir -pv '/media/data/Sorted_iPhone-Music/Television/Marquee Moon ' # dir created then value in variable is no longer there.
+ printf ' \n\n ArtistAlbum 1 -->  \n\n'


#the NewFile name var works as when it re-samples a flac proves that because it has the NewFile name value within it, and afterwords then #it is used again -f "${script_dir}"/"${NewFile}" to check the  to be sure that a file was created if a flac was  re-sampled

all of the variable are either not being set or if they are then they are being lost soon afterwords. Except for NewFile

Code:

Encoding <stdin> to 01 - Albatross.mp3
Encoding as 48 kHz j-stereo MPEG-1 Layer III (4.8x) 320 kbps qval=3
+ printf '\n\n\n\n NewFile -- > 01 - Albatross.mp3 \n\n\n\n'

# after its use it the value is still inside of the variable.

 NewFile -- > 01 - Albatross.mp3

this is the entire script that I added some more to it so it will be there when I get this thing working.
Code:

#!/bin/bash

#Take meta data and use it to rename mp3 files taken off iPhone
# then make directories by band name and album.
#Then copy it into same said directories
#accordingly
#Apr. 06, 2017

working_dir="/media/data/Deluge_Done"
copy_to="/media/data/Sorted_iPhone-Music"
move_to="/media/data/LostTitle_iPhone_Music"
script_dir="~/scripts"


set -x




#find "$working_dir" -type f -name "*.m4a" | while read FILENAME

find "$working_dir" -type f  \( -name '*.mp3' -o -name '*.flac' \) | while read FILENAME
#while read FILENAME
do

#get path - file name - extension

                f=$FILENAME
                path=${f%/*}
                xfile=${f##*/}
                title=${xfile%.*}
                ext=${xfile##*.}
               
        printf "\n\n\n\ this is extension -> $ext\n\n\n\n"
#get needed metadata tag info
ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool  -Title  "$FILENAME" -p '$Title'`"
ALBUM="`exiftool  -Album  "$FILENAME" -p '$Album'`"
GENRE="`exiftool  -Genre  "$FILENAME" -p '$Genre'`"

# create parent directory

mkdir -vp "${move_to}"

# create directories needed for file to be placed in

[[ -n "${ARTIST}" ]] && ( artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}" )

printf "\n artist 1 --> $artist\n\n"
 
[[ -n "${ALBUM}" && -n "${ARTIST}" ]] && ( ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM" ; mkdir -pv "${ArtistAlbum}" )

printf " \n\n ArtistAlbum 1 -->  $ArtistAlbum\n\n"


#Set newFile name for converted flac to mp3
[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

#check for extension type

 printf "next line is to lame flac file\n\n\n\n\n"
 
[[ "${ext}" == 'flac' ]] && flac -cd "$FILENAME" | lame -b 320 - "$NewFile"

# check to be sure file was created

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"

if [[ -f "${script_dir}"/"${NewFile}" ]] ; then
{

id3v2 -A "$ALBUM" "$resampledFileLoc"
id3v2 -a "$ARTIST" "$resampledFileLoc"
id3v2 -t "$TITLE" "$resampledFileLoc"
id3v2 -g "$GENRE" "$resampledFileLoc"

}
fi


#if metadata is empty use file and directories for tags on re-sampled flac files

 file=$FILENAME
 file=${c##*/}
 album=${c#*"${c%/*/"$file"}"/}
 band=${c#*"${c%/*/"$album"}"/}
 band=${band%%/*}
 album=${album%%/*}

if [[ ! -n "$ALBUM" ]] ; then
        #  folder name of that band album added to orginal file.mp3 as tag info
        id3v2 -A "$album" "${FILENAME}"
  # echo  id3v2 -l ${file} " that is new tag added to "
  fi
 

if [[ ! -n "$ARTIST" ]] ; then
        # folder name of artist/band name added to orginal file.mp3 as tag info
        id3v2 -a "$band" "${FILENAME}"
    echo $band " added band to file "
        fi
       
        if [[ ! -n "$TITLE" ]] ; then
  # if no song title in tag info then add orginal file name as tag title info
        id3v2 -t "$pref" "${FILENAME}"
        echo
       
fi


printf "\n\n\ resampledFileLoc --> $resampledFileLoc\n\n\n\n"

#check to be sure it is there again and check to be sure directories to move it to are there before moving 
[[ ! -z "$resampledFileLoc" && -d  "${ArtistAlbum}" ]] && ( mv -v "$resampledFileLoc" "${ArtistAlbum}" )
#; unset ArtistAlbum )


[[ ! -z "$resampledFileLoc" && -d "${artist}" ]] && ( mv -v "$resampledFileLoc" "${artist}" ; unset resampledFIleLoc )
#; unset resampledFIleLoc )


printf "\n\n\n\n here comes the MP3 stuff\n\n\n\n\n"
printf "\n\n\n\n ArtistAlbum --> $ArtistAlbum\n\n"
printf "\n\n artist -- > $artist\n\n"


[[ "${ext}" == 'mp3' && -d "${ArtistAlbum}" ]] && cp -v "$FILENAME"  "${ArtistAlbum}"

[[ "${ext}" == 'mp3' && ! -d "${ArtistAlbum}" && -d "${artist}" ]] && cp -v "${FILENAME}" "${artist}"



#unset ARTIST
#unset TITLE
#unset ALBUM
#unset GENRE
#unset NewFile

done

#< <(find "$working_dir" -type f  \( -name '*.mp3' -o -name '*.flac' \))


BW-userx 04-07-2017 03:58 PM

Quote:

Originally Posted by michaelk (Post 5694019)
Code:

script_dir="~/scripts"
With quotes the ~ is not being expanded to /home/username.

sooo no " " when setting golbals ? ( i think that is what they'd be)
Code:

this
working_dir=/media/data/Deluge_Done
copy_to=/media/data/Sorted_iPhone-Music
move_to=/media/data/LostTitle_iPhone_Music
script_dir=~/scripts
not this
working_dir="/media/data/Deluge_Done"
copy_to="/media/data/Sorted_iPhone-Music"
move_to="/media/data/LostTitle_iPhone_Music"
script_dir="~/scripts"

let me go see what I did a long long time ago in an old script. just to ease my mind.

back

Code:

working_dir="/home/userx/Music"
I used absolute path

better yet
Code:

script_dir="/home/userx/resort-resamplemp3a"
but it still does not explain a few things . let me go back fix that run it again and take a look at it.

BW-userx 04-07-2017 04:23 PM

Just using the Meta Tags example

here we see that YES in fact the value is gotten off the file
Code:


++ exiftool -Artist '/media/data/Deluge_Done/(1977) Marquee Moon/04. Television - Marquee Moon.samantha.mp3' -p '$Artist'
+ ARTIST=Television
++ exiftool -Title '/media/data/Deluge_Done/(1977) Marquee Moon/04. Television - Marquee Moon.samantha.mp3' -p '$Title'
+ TITLE='Marquee Moon'
++ exiftool -Album '/media/data/Deluge_Done/(1977) Marquee Moon/04. Television - Marquee Moon.samantha.mp3' -p '$Album'
+ ALBUM='Marquee Moon '
++ exiftool -Genre '/media/data/Deluge_Done/(1977) Marquee Moon/04. Television - Marquee Moon.samantha.mp3' -p '$Genre'
+ GENRE=Post-Punk
+ printf '\n\n Meta tags -> Television - Marquee Moon - Marquee Moon  - Post-Punk \n\n'
Meta tags -> Television - Marquee Moon - Marquee Moon  - Post-Punk

this data is used to create a directory structure by ARTIST ALBUM using the copy_to= as well

I test to be sure that their is a value within the ARTIST and ALBUM first because I already know their is a value in
copy_to

Code:

copy_to="/media/data/Sorted_iPhone-Music"
[[ -n "${ARTIST}" ]] && ( artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}" )

if true then put all of the path into a variable then next using the semi colon create the directory structure which is created.
then what is inside of $artist is immediately lost afterwords.
we see that here.
Code:


+ [[ -n Television ]]
+ artist=/media/data/Sorted_iPhone-Music/Television
+ mkdir -pv /media/data/Sorted_iPhone-Music/Television


# the directory is created yes, then value in side of variable is lost immediately afterwords, which I've coded\
# like this before and never had this happen to be before.
# I can post an old script too if you want me to. :D

+ printf '\n artist 1 --> \n\n'

printf '\n artist 1 --> [ there should be the absolute path right here like this /media/data/Sorted_iPhone-Music/Television ] \n\n'

this s the printf code
Code:

printf "\n artist 1 --> $artist\n\n"

BW-userx 04-07-2017 04:59 PM

THIS WORKS! no variable values are being lost at all..
MIND you this is a completely different script but the same logic and data extraction and test are being used

I dug this one out of all of the old scripts I have, I thought I'd lost it --- but still
Code:

#!/bin/bash

#set -x

count=0 max=0


#void Linux
working_dir="/media/data/Deluge_Done"


#Slackware
#working_dir="/run/media/userx/WorkingDirMP3"

#void Linux
move_to="/media/data/FinishTest"

#Slackware
#move_to="/run/media/userx/iTunesMusic"

script_dir=~/scripts

max="$(find "$working_dir" -type f -name "*.mp3" | wc -l)"

while read FILENAME
do

ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool  -Title  "$FILENAME" -p '$Title'`"
ALBUM="`exiftool  -Album  "$FILENAME" -p '$Album'`"
#GENRE="`exiftool  -Genre  "$FILENAME" -p '$Genre'`"

  #unsets formating of string making it left alined.
  set -- $ARTIST
  ARTIST="$@"

  set -- $ALBUM
  ALBUM="$@"
 
  set -- $TITLE
  TITLE="$@"
 
#  set -- $GENRE
#  GENRE="$@"

 #writes name to mp3 tag info

        eyeD3 -a "$ARTIST" "$FILENAME"
        eyeD3 -A "$ALBUM" "$FILENAME"
        eyeD3 -t "$TITLE" "$FILENAME"
        #eyeD3  --remove-all-comments "$FILENAME"
       
  #create and move file into respective areas
[[ -n "$ARTIST" && -n "$ALBUM" ]] && ( copyTo="$move_to/$ARTIST/$ALBUM" ; mkdir -pv "$copyTo" ; cp -v "$FILENAME"  "$copyTo" )
       
        echo "
                        MAX    is $max
                        count  is $((++count))
                                --------
                                  $((max - count))
                "
                   
done < <(find "$working_dir" -type f -name "*.mp3")

KEY POINTS
Code:


[[ -n "$ARTIST" && -n "$ALBUM" ]] && ( copyTo="$move_to/$ARTIST/$ALBUM" ; mkdir -pv "$copyTo" ; cp -v "$FILENAME"  "$copyTo" )

it does not lose its value

but that other one where I combined mp3 and flac which I have done countless times to be processed at the same time is not working properly WHY?

michaelk 04-07-2017 05:54 PM

Does not work as for me either. Try removing the parenthesis.

Code:

[[ -n "${ARTIST}" ]] &&  artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}"

astrogeek 04-07-2017 05:57 PM

... none of which answered my request...

The point of troubleshooting is to isolate the point at which some unexpected behavior occurs, and identify the specific cause.

The point of asking for an exact, simplest case is to help you isolate both what is happening and where it is happening.

In the process of attempting to provide those answers you will either provide us the information we need to understand the problem, or often as not, you will find that the problem is not what you thought it was... either way it is progress!

Not attempting to answer those questions as asked leaves us several lengthy posts later, no closer to understanding the actual problem. Changing to another script entirely is also not helpful as the proverbial wild geese typically enter at that point...

The debugging output produced by set -xv is mostly helpful to the person sitting at the keyboard. It is a powerful option to help you interactively isolate and identify what your code is actually doing at runtime. We cannot participate in that interactive debugging process, so posting the debugging output is less helpful to us. What is helpful to us is attempting to provide the results of your own interactive use of that debugging output, the isolated errant code.

You have posited that some variable was losing its value after some test. Repeatedly justifying that conclusion with lengthy debugging output is not helpful. Attempting to isolate the point at which the variable loses its value, as reqquested would be helpful to us and to you.

You will often see people here ask, "Help us help you". This is one of those times.

BW-userx 04-07-2017 06:53 PM

OK RESET EVERY THING I rewrote the entire script and am still getting the same problem.

let me see which first, script or results?

script is this
Bold shows code to print value in variable

Code:

#!/bin/bash

working_dir=/media/data/Deluge_Done

move_to=/media/data/Sorted_iPhone-Music

script_dir=/home/userx/scripts

#set -x

while read FILENAME
do

f=$FILENAME
path=${f%/*}
xfile=${f##*/}
title=${xfile%.*}
ext=${xfile##*.}

ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool -Title "$FILENAME" -p '$Title'`"
ALBUM="`exiftool -Album "$FILENAME" -p '$Album'`"
GENRE="`exiftool -Genre "$FILENAME" -p '$Genre'`"

[[ -n "$ALBUM" && -n "$ALBUM" ]] && ( ArtistAlbum="$move_to/$ARTIST/$ALBUM" ; printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n" ;  mkdir -pv "$ArtistAlbum" )

printf " num 2 ArtistAlbum -> $ArtistAlbum\n"

#It does not get this far down in the script because the first file meets the conditions of the first test

[[ "$ext" == 'flac' && -n "$ALBUM" && -n "$ARTIST" ]] && ( NewFile="$title"."mp3" ; flac -cd "$FILENAME" | lame -b 320 - "$NewFile" ; printf "num 3 script_dir - NewFile -> $script_dir/$NewFile\n $ArtistAlbum\n" ;  mv -v "$script_dir/$NewFile" "$ArtistAlbum" \
id3v2 -A "$ALBUM" "$ArtistAlbum/$NewFile" ; id3v2 -a "$ARTIST" "$ArtistAlbum/$NewFile" ; id3v2 -t "$TITLE" "$ArtistAlbum/$NewFile" ; id3v2 -g "$GENRE" "$ArtistAlbum/$NewFile" )


[[ ! -n "$ALBUM" && -n "$ARTIST" ]] && ( Artist="$move_to/$ARTIST" ; mkdir -pv "$Artist" )

printf "Artist - > $Artist\n"

[[ "$ext" == 'flac' && -n "$ARTIST" &&  ! -n "$ALBUM" ]] && ( NewFile="$title"."mp3" ; flac -cd "$FILENAME" | lame -b 320 - "$NewFile" ;  printf "script_dir - NewFile -> $script_dir/$NewFile\n" ; mv -v "$script_dir/$NewFile" "$Artist" \
id3v2 -A "$ALBUM" "$Artist/$NewFile" ; id3v2 -a "$ARTIST" "$Artist/$NewFile" ; id3v2 -t "$TITLE" "$Artist/$NewFile" ; id3v2 -g "$GENRE" "$Artist/$NewFile" )



done < <( find "$working_dir" -type f -name "*.flac" )

results bold shows the variable with value then when it is gone after being used.
Code:

userx@slackwhere⚡~/scripts $./resample-flacy
num 1 . ArtistAlbum -> in create dir /media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box
num 2 ArtistAlbum ->

flac 1.3.1, Copyright (C) 2000-2009  Josh Coalson, 2011-2014  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

01 - Albatross.flac: done       
LAME 3.99.5 64bits (http://lame.sf.net)
Resampling:  input 96 kHz  output 48 kHz
Using polyphase lowpass filter, transition band: 20323 Hz - 20903 Hz
Encoding <stdin> to 01 - Albatross.mp3
Encoding as 48 kHz j-stereo MPEG-1 Layer III (4.8x) 320 kbps qval=3
num 3 script_dir - NewFile -> /home/userx/scripts/01 - Albatross.mp3
 
mv: target ' ' is not a directory
Couldn't stat file '/01 - Albatross.mp3'
Couldn't stat file '/01 - Albatross.mp3'
Couldn't stat file '/01 - Albatross.mp3'
Couldn't stat file '/01 - Albatross.mp3'
Artist - >

It is loosing the value in the variable "$ArtistAlbum" it is the target directory but because it lost its value right after it creates the directory. it shows this instead mv: target ' ' is not a directory


now what are your thoughts on this?

sorry but I felt if a rewrite was done it might just work. and be less confusing to read. so I condensed everything for you ;)

looks nice huh? :D

BW-userx 04-07-2017 07:10 PM

I did a reassment on that var and reset it to the proper vaule but am still getting

Code:

+ mv -v '/home/userx/scripts/02 - Memories.mp3' '/media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box' ' '
mv: target ' ' is not a directory

that ' ' ' I need to figure out where that is coming from.
Code:



[[ "$ext" == 'flac' && -n "$ALBUM" && -n "$ARTIST" ]] && ( NewFile="$title"."mp3" ; flac -cd "$FILENAME" | lame -b 320 - "$NewFile" ; printf "num 3 script_dir - NewFile -> $script_dir/$NewFile\n $ArtistAlbum\n" ;  mv -v "$script_dir/$NewFile" "$ArtistAlbum" \
id3v2 -A
"$ALBUM" "$ArtistAlbum/$NewFile" ; id3v2 -a "$ARTIST" "$ArtistAlbum/$NewFile" ; id3v2 -t "$TITLE" "$ArtistAlbum/$NewFile" ; id3v2 -g "$GENRE" "$ArtistAlbum/$NewFile" )

it has to be somewhere between that bold part maybe the \ is too far spaced out. checking....


the reassignment btw
Code:


ArtistAlbum="$move_to/$ARTIST/$ALBUM"

printf " num 2 ArtistAlbum -> $ArtistAlbum\n"


BW-userx 04-07-2017 07:15 PM

ahhhhh now I am getting crazy stuff

I moved the space between the ; "command" \next line
then hit enter to put it on the next line and now I am getting this.
Code:

; "command \
next line

Code:

+ mv -v '/home/userx/scripts/03 - Poptones.mp3' '/media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box' id3v2 -A 'Metal Box' '/media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box/03 - Poptones.mp3'
mv: invalid option -- 'A'
Try 'mv --help' for more information.

I have no idea where it is seeing I have an option 'A' in there. Just look back at the code. nothing changed but the spacing.

on I look at it again in the post.. I can see what it is now. got a go check it. prob forgot a ';' semi-colon

michaelk 04-07-2017 07:24 PM

I would suggest not using conditional execution and go back to a regular if then statement.
Code:

if [[ -n "$ALBUM" && -n "$ALBUM" ]];then
  ArtistAlbum="$move_to/$ARTIST/$ALBUM"
  printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n"
  mkdir -pv "$ArtistAlbum"
fi


BW-userx 04-07-2017 07:31 PM

Quote:

Originally Posted by michaelk (Post 5694102)
I would suggest not using conditional execution and go back to a regular if then statement.
Code:

if [[ -n "$ALBUM" && -n "$ALBUM" ]];then
  ArtistAlbum="$move_to/$ARTIST/$ALBUM"
  printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n"
  mkdir -pv "$ArtistAlbum"
fi


naaa that is no fun it is made to work like I wrote it. I read up on it.

the only puzzle here is why did ArtistAlbum lose it's value after it was used once?

if I do your code then another printf is needed to see if that way does not lose ArtistAlbum value after the mkdir. if it does then what's UP?

I'll get back to you on this.

as it stand it is now working as it should. with my conditional executions one liners.


Code:

if [[ -n "$ALBUM" && -n "$ALBUM" ]];then
  ArtistAlbum="$move_to/$ARTIST/$ALBUM"
  printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n"
  mkdir -pv "$ArtistAlbum"
fi
printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n"


BW-userx 04-07-2017 07:50 PM

just for a follow up on @michaelk advice

used his conditional block statement
Code:

if [[ -n "$ALBUM" && -n "$ALBUM" ]];then
  ArtistAlbum="$move_to/$ARTIST/$ALBUM"
  printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n"
  mkdir -pv "$ArtistAlbum"
fi

printf " num 4343 ArtistAlbum -> in create dir $ArtistAlbum\n"

Positive results were positive no reassignment of variable needed.

Code:

userx@slackwhere⚡~/scripts $./resample-flacy
 num 1 . ArtistAlbum -> in create dir /media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box
mkdir: created directory '/media/data/Sorted_iPhone-Music'
mkdir: created directory '/media/data/Sorted_iPhone-Music/Public Image Ltd.'
mkdir: created directory '/media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box'
num 4343 ArtistAlbum -> in create dir /media/data/Sorted_iPhone-Music/Public Image Ltd./Metal Box

still keeping my one liners :D thanks


someone submit a bug report -- for one liner conditionals losing variable value after first use. not me I'm busy. :rolleyes:

working script for the masses to see what I did to fix it. and make note that @michaelk works too. Moral of the story. There is more then one way to skin
a cat (methodology) kids. :hattip:


Code:


#!/bin/bash

working_dir=/media/data/Deluge_Done

move_to=/media/data/Sorted_iPhone-Music

script_dir=/home/userx/scripts

#set -x

while read FILENAME
do

f=$FILENAME
path=${f%/*}
xfile=${f##*/}
title=${xfile%.*}
ext=${xfile##*.}

ARTIST="`exiftool -Artist "$FILENAME" -p '$Artist'`"
TITLE="`exiftool -Title "$FILENAME" -p '$Title'`"
ALBUM="`exiftool -Album "$FILENAME" -p '$Album'`"
GENRE="`exiftool -Genre "$FILENAME" -p '$Genre'`"

[[ -n "$ALBUM" && -n "$ALBUM" ]] && ( ArtistAlbum="$move_to/$ARTIST/$ALBUM" ; printf " num 1 . ArtistAlbum -> in create dir $ArtistAlbum\n" ;  mkdir -pv "$ArtistAlbum" )


ArtistAlbum="$move_to/$ARTIST/$ALBUM"


[[ "$ext" == 'flac' && -n "$ALBUM" && -n "$ARTIST" ]] && ( NewFile="$title"."mp3" ; flac -cd "$FILENAME" | lame -b 320 - "$NewFile" ; printf "num 3 script_dir - NewFile -> $script_dir/$NewFile\n $ArtistAlbum\n" ;  mv -v "$script_dir/$NewFile" "$ArtistAlbum" ; \
id3v2 -A "$ALBUM" "$ArtistAlbum/$NewFile" ; id3v2 -a "$ARTIST" "$ArtistAlbum/$NewFile" ; id3v2 -t "$TITLE" "$ArtistAlbum/$NewFile" ; id3v2 -g "$GENRE" "$ArtistAlbum/$NewFile" )


[[ ! -n "$ALBUM" && -n "$ARTIST" ]] && ( Artist="$move_to/$ARTIST" ; mkdir -pv "$Artist" )

 Artist="$move_to/$ARTIST"

[[ "$ext" == 'flac' && -n "$ARTIST" &&  ! -n "$ALBUM" ]] && ( NewFile="$title"."mp3" ; flac -cd "$FILENAME" | lame -b 320 - "$NewFile" ;  printf "script_dir - NewFile -> $script_dir/$NewFile\n" ; mv -v "$script_dir/$NewFile" "$Artist" ; \
id3v2 -A "$ALBUM" "$Artist/$NewFile" ; id3v2 -a "$ARTIST" "$Artist/$NewFile" ; id3v2 -t "$TITLE" "$Artist/$NewFile" ; id3v2 -g "$GENRE" "$Artist/$NewFile" )



done < <( find "$working_dir" -type f -name "*.flac" )


BW-userx 04-07-2017 07:55 PM

Quote:

Originally Posted by astrogeek (Post 5694079)
... none of which answered my request...

The point of troubleshooting is to isolate the point at which some unexpected behavior occurs, and identify the specific cause.

I showed my code that was giving me bad results and I showed what set -x was showing not set -xv but set -x which shows values in variables. that showed the results of said code.

no more or less than I have to work with to figure it out. so I do not understand your statements

which was as it turns out only one issue that I'd messed up on.

you say to not rewrite the code it is like chasing ducks another asks me to rewrite it so it only shows what is erroring.

rewriting what I rewrote it fixed a lot of it until I did get it down to just one issue that someone else helped me with. that was not the one I posted on but never the less it was still there within that code.

More than one were error-ing in losing value so to isolate it when everything is leaking still takes more then you expected me to show you.

BW-userx 04-07-2017 08:06 PM

Quote:

Originally Posted by astrogeek (Post 5694008)
I have not been able to make sense of the original question or the following test case.

Please show us this and exactly this so that we can understand it and repeat it...

* Some variable with a value, echo that value
* Your test of that variable from your code which you say is affecting the variable value
* That same variable value after the test at which point you say has lost its value

I could not make sense out of it either perhaps that is why you could not. But that is why I posted it.

NevemTeve 04-07-2017 11:42 PM

You were asked to provide a minimal complete example. You don't know what this means, or simply don't feel like doing it?

astrogeek 04-08-2017 01:50 AM

I set aside some time to re-read the entire thread to try to make sense of the problem. I am confident that I now see the source of some, hopefully the, "lost" variable values.

Limiting the test cases to the code and debug data posted in #3 and assuming that the "it" you refer to is either or both of artist and ArtistAlbum when you say...

Quote:

it is no longer for what the description says its for. I just kept some of it, and rewrote the body of it to re-sample flac and copy mp3s from somewhere else into a different file structure
You set artist in a subshell in line 49...

Code:

[[ ! -z "${ARTIST}" ]] && ( artist="$copy_to"/"$ARTIST" ; mkdir -pv "${artist}" )
...then test for it in lines 74 and 84...

Code:

[[ ! -z "resampledFileLoc" && -d "${artist}" ]] && ( mv -v "resampledFileLoc" "${artist}" ; unset resampledFIleLoc )
...
[[ "${ext}" == 'mp3' && ! -d "${ArtistAlbum}" && -d "${artist}" ]] && cp -v "${FILENAME}" "${artist}"

You set the value of artist inside a subshell, (...), it is NEVER set in the shell in which the main body of the script is running, and where the tests are executed. To fix that, rethink the parenthesis as suggested by michaelk in post #12.

Also, unset resampledFIleLoc has no effect outside the subshell in which it is executed in that line.

Same for ArtistAlbum, you set it in line 51, inside a subshell...

Code:

[[ ! -z "${ALBUM}" && ! -z "${ARTIST}" ]] && ( ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM" ; mkdir -pv "${ArtistAlbum}" )
...then test for it in lines 71 (and unset it in another subshell...), 82 and 84...

Code:

[[ ! -z "resampledFileLoc" && -d  "${ArtistAlbum}" ]] && ( mv -v "resampledFileLoc" "${ArtistAlbum}" ; unset ArtistAlbum )
...
[[ "${ext}" == 'mp3' && -d "${ArtistAlbum}" ]] && cp -v "$FILENAME"  "${ArtistAlbum}"

[[ "${ext}" == 'mp3' && ! -d "${ArtistAlbum}" && -d "${artist}" ]] && cp -v "${FILENAME}" "${artist}"

There are still a few un-tamed geese in this thread and the snippets quoted above, but I suspect these cases cover the original problem.

I will ask again that in future you please try to be more precise in your problem descriptions (refer to things explicitly by name and avoid using vague and ambiguous references such as "it" above). And post debugging output sparingly - it is mostly useful to you interactively and often clutters our ability to see the actual problem.

Make effort to reduce the problem to some simplest, minimal test case which demonstrates it clearly (using the debug output), then post that simplest case if the problem still exists.

And please try to respond to requests for specific information with that specific information. Reducing a problem to a simplest example will almost always lead directly to the problem, as I think it would have done here.

Again, please help us help you, and respect the time and efforts of others by helping them to apply their effort efficiently.

ondoho 04-08-2017 01:58 AM

Quote:

Originally Posted by BW-userx (Post 5694116)
Code:

if [[ -n "$ALBUM" && -n "$ALBUM" ]];

what is this supposed to accomplish?

pan64 04-08-2017 02:16 AM

you need to use { } instead of ( ), that will probably solve some of your issues.
If that was unclear: ( something ) means something will be executed in a new shell (which is actually a child of the "current" shell - or just named subshell). This subshell cannot reach/access the environment of its parent, so for example cannot change its variables.

And another tip (which will not solve anything, just will simplify things a bit):
Code:

# instead of:
ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM"
# you can write:
ArtistAlbum="$copy_to/$ARTIST/$ALBUM"

here:
Code:

[[ ! -z "resampledFileLoc" && -d "${artist}" ]] && ( mv -v "resampledFileLoc" "${artist}" ; unset resampledFIleLoc )
        $                                                  $

you just missed the $ in front of the variable names.

BW-userx 04-08-2017 07:45 AM

Quote:

Originally Posted by pan64 (Post 5694210)
you need to use { } instead of ( ), that will probably solve some of your issues.
If that was unclear: ( something ) means something will be executed in a new shell (which is actually a child of the "current" shell - or just named subshell). This subshell cannot reach/access the environment of its parent, so for example cannot change its variables.

And another tip (which will not solve anything, just will simplify things a bit):
Code:

# instead of:
ArtistAlbum="$copy_to"/"$ARTIST"/"$ALBUM"
# you can write:
ArtistAlbum="$copy_to/$ARTIST/$ALBUM"

here:
Code:

[[ ! -z "resampledFileLoc" && -d "${artist}" ]] && ( mv -v "resampledFileLoc" "${artist}" ; unset resampledFIleLoc )
        $                                                  $

you just missed the $ in front of the variable names.

This is already been marked solved. please go look at post # 19 to see the entire script in working order. :D

as you stated that is what I was going to put to the test today. Having given it more thought after I posted is to try the { } vs ( ) because I'd remembered something about what I read said something about how ( ) creates another shell and { } does not. so if I remember correctly, when that happens and a Variable is used it cannot pass values between them.

like loops cannot passing values into another loop if I think it is from out side loop to inside loop, and from an inside loop it can be pass to the outside loop, or visa versa. I do not do that enough to remember exactly.

Only that the ( ) creates a separate shell so when the Variable was set then used when it came back its value was lost due to that effect.

I was going to test that today...

BW-userx 04-08-2017 08:02 AM

Quote:

Originally Posted by ondoho (Post 5694206)
what is this supposed to accomplish?

cause due to hack job, copy paste, as I stated in a post in here. I hacked this together.

As well as got yelled at for changing my code while some others (you included) were trying to figure it out.

well I didn't feel like sitting here with my thumb up my butt and letting everyone figure out all of my mistakes for me when I have the abilities to help figure out my own mistakes at the same time. That is why I posted my changes to show the progress and to update them that were trying to help.

I got a lecture out of that one from someone in here.

BW-userx 04-08-2017 08:20 AM

Quote:

Originally Posted by NevemTeve (Post 5694175)
You were asked to provide a minimal complete example. You don't know what this means, or simply don't feel like doing it?

I gave out all of the information needed to have someone else see what I did not.

I gave the proper example that is to be used to do what I was doing and sighted the web page I got it from.
Post #1
Quote:

if [ -f /var/log/messages ]
then
echo "/var/log/messages exists."
fi
I gave out the proper offending code that was causing the error
post #1
Quote:

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"
I gave out the proper error message to show how it was producing the error
post #1
Quote:

+ [[ -f ~/scripts/01 - Albatross.mp3 ]]

#
# It tested true but did not set the variable The next line proves it.
#
+ printf '\n\n\ resampledFileLoc --> \n\n\n\n'
\ resampledFileLoc -->

#
# nothing was inside of it
#
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
then you asked me to rewrite it into a script that will isolate that error. what part of that can't you use to figure it out without me having to do this.

Code:

#!/bin/bash

script_dir="~/scripts"



# to egt the file name so I can rename it
find "$working_dir" -type f  \( -name '*.mp3' -o -name '*.flac' \) | while read FILENAME
#while read FILENAME
do

#get path - file name - extension

                f=$FILENAME
                path=${f%/*}
                xfile=${f##*/}
                title=${xfile%.*}
                ext=${xfile##*.}

#Set newFile name for converted flac to mp3

[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"

done

just so you can see the same error from set -x which would be the same thing

right here
post #1
Quote:

+ [[ -f ~/scripts/01 - Albatross.mp3 ]]

#
# It tested true but did not set the variable The next line proves it.
#
+ printf '\n\n\ resampledFileLoc --> \n\n\n\n'
\ resampledFileLoc -->

#
# nothing was inside of it
#
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
where
Quote:

Quote:

Originally Posted by michaelk (Post 5694019)
Code:

script_dir="~/scripts"
With quotes the ~ is not being expanded to /home/username.


michaelk picked up on it. using what I gave out. That set me in the right direction to going back to using absolute path instead.

so your request holds no water and I seen that as soon as I seen your request, and to me is was waste of time to have obeyed your request. so I did not. Due to what I already stated.

as well as I would have done just what I've done to someone script to try and help them out with it if needed.

I'll write out their script and try to get it to work, and if I do I'll show them how I did it and sometimes left out something or a clue on how to and tell them about it, so they can use their brain as well. In hopes that they learn how to use their own brain to figure out problems on there own instead of always relying on others to figure out all of their problems for them.


that is not to say that everyone just needs to just figure their own problems out themselves as everyone does need a little help now and then.

P.S> and yes there was more to do, and I got yelled at (or a stern talking to) for doing so. along with the all of you.

BW-userx 04-08-2017 08:22 AM

**** please note that this post has been marked solved. I am not going to waste anymore electronic paper on it. *****

it was marked solved at post # 19
the only thing I am going to do is test

{ } vs ( )

that I thought of yesterday after singing off for the day, and then someone seen it too and posted about it in here as well. After I marked it solved. Which only confirms my suspicions on it.

[ points given to them that I gave them to ]
Thank you
and
Happy Canonic
:party:

NevemTeve 04-08-2017 09:31 AM

Additional reading: http://stackoverflow.com/help/mcve

BW-userx 04-08-2017 09:45 AM

Quote:

Originally Posted by NevemTeve (Post 5694293)

going to make a liar out of me aren't you? I already said I was not going to post in here anymore.

The precious test script you insisted you had to have or you could not evaluate anything by using anything that I already posted.
Code:

#!/bin/bash

working_dir=/media/data/Deluge_Done
script_dir="~/scripts"

set -x


# to egt the file name so I can rename it
find "$working_dir" -type f  -name '*.flac'  | while read FILENAME
do

#get path - file name - extension

                f=$FILENAME
                path=${f%/*}
                xfile=${f##*/}
                title=${xfile%.*}
                ext=${xfile##*.}

#Set newFile name for converted flac to mp3

[[ "${ext}" == 'flac' ]] && NewFile="$title"."mp3"

[[ -f "${script_dir}"/"${NewFile}" ]] && resampledFileLoc="${script_dir}"/"${NewFile}"

printf "resampledFileLoc --> $resampledFileLoc\n"

exit 0

done

the test results
Code:

userx@slackwhere⚡~/scripts $./test-prove-point-script
+ find /media/data/Deluge_Done -type f -name '*.flac'
+ read FILENAME
+ f='/media/data/Deluge_Done/1979 - Public Image Ltd. - Metal Box [Virgin Vinyl 24-96 FLAC][2009][Kel Bazar]/01 - Albatross.flac'
+ path='/media/data/Deluge_Done/1979 - Public Image Ltd. - Metal Box [Virgin Vinyl 24-96 FLAC][2009][Kel Bazar]'
+ xfile='01 - Albatross.flac'
+ title='01 - Albatross'
+ ext=flac
+ [[ flac == \f\l\a\c ]]
+ NewFile='01 - Albatross.mp3'
+ [[ -f ~/scripts/01 - Albatross.mp3 ]] <----------
+ printf 'resampledFileLoc --> \n' <----------
resampledFileLoc --> <----------
+ exit 0

My Original post showing the error

Code:




now comes the check to insure that a file was re-sampled
Code:

 
+ [[ -f ~/scripts/01 - Albatross.mp3 ]] <----------
#
#  It tested true but did not set the variable The next line proves it.
#
+ printf '\n\n\ resampledFileLoc --> \n\n\n\n' <----------
\ resampledFileLoc --> <----------

#
# nothing was inside of it
#
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]
+ [[ ! -z resampledFileLoc ]]
+ [[ -d '' ]]


do you notice any similarities whatsoever?

again that is a waste of my time to have done as you requested. As I stated WHY just so you can see the very same results of what I already posted?


again here is someone that surely does not need to live by someone else rule that obviously is not a complete true (brief) statement.


Quote:


where
Quote:

Quote:

Originally Posted by michaelk (Post 5694019)
Code:

script_dir="~/scripts"
With quotes the ~ is not being expanded to /home/username.


michaelk picked up on it. using what I gave out. That set me in the right direction to going back to using absolute path instead.
that made up requirement came from some lazy A$$ half baked thought.

so who now needs to recalibrate their belief system?

astrogeek 04-08-2017 12:07 PM

Quote:

Originally Posted by BW-userx (Post 5694297)
again that is a waste of my time to have done as you requested. As I stated WHY just so you can see the very same results of what I already posted?
...
again here is someone that surely does not need to live by someone else rule that obviously is not a complete true (brief) statement.
...
that made up requirement came from some lazy A$$ half baked thought.

so who now needs to recalibrate their belief system?

BW-userx, rude and insulting remarks, personal attacks and namecalling WILL NOT BE TOLERATED in this forum.

You consider it a waste of your time to provide simple answers to direct questions, yet you waste the time of everyone else who is trying to help you by not responding to their requests for ordinary clarification of your problem.

Please see, again, then basic rules of the forum, inclucing this:

Quote:

If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere.

BW-userx 04-08-2017 12:18 PM

Quote:

Originally Posted by astrogeek (Post 5694344)
BW-userx, rude and insulting remarks, personal attacks and namecalling WILL NOT BE TOLERATED in this forum.

You consider it a waste of your time to provide simple answers to direct questions, yet you waste the time of everyone else who is trying to help you by not responding to their requests for ordinary clarification of your problem.

Please see, again, then basic rules of the forum, inclucing this:

where were my remarks rude?

I was just pointing out truths.

I provided a proof to a remark to me that his request was not valid. where he kept on insisting that is was.

So I gave him Proof that No it was not valid that in fact he was in error of his thinking

where is the rudeness in that?

to prove someone wrong is not being rude

as far as this goes
"that made up requirement came from some lazy A$$ half baked thought."

it was to the one that made up that "rule" no one here in LQ did it that was from another web sight
stackoverflow

motivational psychology tells me that it was someone that is too lazy to put the effort into it themselves.
as well as if a person provides what I did then that does not need to be done. if at all. as I put forth proof to that effect.

that was a comment about some one that is not even in LQ but stackoverflow ....

BW-userx 04-08-2017 01:08 PM

@astrogeek

further more

Quote:

again here is someone that surely does not need to live by someone else rule that obviously is not a complete true (brief) statement.
that is a true statement as the user who is a moderator user name michaelk
figured it out without having me rewite an enter bash script to only show the same error as before it'd had been rewritten.


therefore that is a truth

please explain to me how telling the truth in your book as someone that is being rude?


Quote:

...
that made up requirement came from some lazy A$$ half baked thought.
that is about someone in stack exchange web sight ... let him defend himself if he wants to to me.
Quote:

so who now needs to recalibrate their belief system?

that is a question not a statement for one.

please explain to me how a question is being rude to someone in your book?

if someone makes a mistake in codding it is because they believed what they were doing was right.

then that someone comes in here and asks why is what I believe to be right not working?

others look at the problem see the error then corrects them because they where in error of their thinking that is why they were getting errors in their code.

so someone recalibrate that persons belief system by correcting them and showing them their errors and how to fix them


I did the same with not code but ones thinking


their is no difference in the methodology whatsoever only where it has been ap;plied.

where is the rudeness in showing ones fellow man their errors in thinking so they will no longer be in error of themselves in what they do, be it in what they are coding or how they are communicating to others?

because coding is too a form of communication same as someone communicating to another by whatever means.


It was a Question not a statement meant to bring a thought to someones mind After showing them their error in thinking .. that perhaps they need to rethink their belief about what one HAS to do for him in order to get him to be able to get the very same results that michaelk got when he did not have to have the same information given to him.

that being an entirely different script that will only reproduce the exact same error that I showed already and the code that did it.


all having to be put into a different bash script to get the exact same results. why ?

because that persons thinking is in error and it came from his belief system if you know how a belief system works that would help . I will explain that to you to help you better understand what it is that really happened here.

it is because that person held the belief that I ( and others) have to rewrite the code into a different file so that it only shows that one error so the one looking at the code that is throwing the error can be found easier.

an act of laziness because they do not want to have to go through all of that code to try and find it.

when a real coder has to.

I proved what was needed and then asked to give more.



if one picks out what is causing it and the error as a result of it. then no entirely new file is needed to be created.

I do not see this request for every question in Linux Questions for everyone that provides a question on why is this erroring on me?


so why is it that when I get this request more then once to the point I feel the need to show that person that his requested is invalid and prove it. then put to question that perhaps someone is in need to rethink what it is that they believe to be e truth when in fact it is not

because I proved it that it is not a necessary.

therefore proving that that belief is not a absolute truth.

to try and help someone in their thinking

that is all that was and that is it

and you see it as being RUDE?

Why?

astrogeek 04-08-2017 01:36 PM

This is neither a courtroom nor a kindergarten where we play games of, "Did too! Did not! Did too! Did not!", verbal misdirection and laying of blame.

This is a technical forum where we operate on a fully adult, respectful and cooperative level.

Please demonstrate that you are willing to do so.

This thread is now closed.


All times are GMT -5. The time now is 08:46 PM.