[SOLVED] here's a brain teaser, for some. bash output to current dir, how to redirect it?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
here's a brain teaser, for some. bash output to current dir, how to redirect it?
I got a script that where ever it is ran this is the output to lame or flac, then it picks up the file in that dir and moves it accordingly. If I am not in the same dir that the script is when I start the script from the cli, then the output is where ever current dir is. therefore, screwing up the code telling it where to get the final product from lame so I can move it accordingly.
wmbutton, I set one button up to call the script to be stared in a terminal, forgetting about that part (above) until I seen it's output file not found.
I could not find how to get a terminal to change into a dir when being started.
Code:
Eterm/xterm/uxterm -e "cd /some other dir"
Eterm/xterm/uxterm -c "cd /some other dir"
but the dir is my home dir that is being used to dump my files into because that is where the script shell is started in, and not the dir the script is actually in.
therefore in order to get my script to know where they are at at all times, due to depending on where or how I start that script. what means would I use to do that?
can it be done?
Code:
#!/bin/bash
script_dir=/media/data1/scripts/
working_dir="/media/data1/music-files-to-do"
move_to=/media/ntfs1/done1-Music
if [[ -d /run/media/userx/3TB-External ]] ; then
{
copy_to=/run/media/userx/3TB-External/done1-Music
}
elif [[ -d /media/userx/3TB-External ]] ; then
{
copy_to=/media/userx/3TB-External/done1-Music
}
fi
no_tags=/media/ntfs1/music.No.Tags
if [[ ! -d "${copy_to%/*}" ]] ; then
echo "drive $copy_to not mounted"
exit
fi
count="$(find "$working_dir" -type f -iname "*.mp3" -o -iname "*.flac" | wc -l)"
while read f ; do
d=$f
path=${d%/*}
name=${d##*/}
filename=${name%.*}
ext=${name##*.}
newFile="$filename"."mp3"
newDirStruct=${path/$working_dir/$move_to}
newCopyTo=${path/$working_dir/$copy_to}
NoTags=${path/$working_dir/$no_tags}
echo
echo "$((count--)) :Left:"
echo
bitrate="$(exiftool -p '$AudioBitrate' "$f")"
#strips kpbs
bitrate=${bitrate% *}
echo "$bitrate"
artist="$(exiftool -p '$Artist' "$f")"
album="$(exiftool -p '$Album' "$f")"
title="$(exiftool -p '$Title' "$f")"
genre="$(exiftool -p '$Genre' "$f")"
#changed to Meta Tag info dir structure
move_new="$move_to"/"$artist"/"$album"
copy_new="$copy_to"/"$artist"/"$album"
##############################################################
# Resampling with LAME 99.9.5
# if MP3 is out of limits then re-sample it if not then send it through
# skip resampling saves time
###
# flac -cd "$f" | lame -b 320 - "${f%.*}".mp3
if [[ "${ext}" == 'flac' ]] ; then
{
4 flac -cd "$f" | lame -V 5 -b 128 -F --vbr-new -m j -q 2 - "$newFile"
rm -v "$f"
bitrate="$(exiftool -p '$AudioBitrate' "$script_dir"/"$newFile")"
#strips kpbs
bitrate=${bitrate% *}
echo ":BiTRATE:2 is :: $bitrate"
mid3v2 -a "$artist" "$script_dir"/"$newFile"
mid3v2 -A "$album" "$script_dir"/"$newFile"
mid3v2 -t "$title" "$script_dir"/"$newFile"
mid3v2 -g "$genre" "$script_dir"/"$newFile"
artistAlbum="$artist"/"$album"
if [[ -n "$artist" && -n "$album" ]] ; then
{
mkdir -p "$move_new"
mkdir -p "$copy_new"
cp -r "$script_dir"/"$newFile" "$copy_new"
mv -vf "$script_dir"/"$newFile" "$move_new"
}
else
{
mkdir -p "$NoTags"
mv -vf "$script_dir"/"$newFile" "$NoTags"
}
fi
} # if start bitrate < 128 or start bitrate > 160 then resample
elif [[ "${bitrate%.*}" -gt "${rate2h}" ]] ; then
{
lame -V 5 -b 128 -F --vbr-new -m j -q 2 "$f" "$newFile"
rm -v "$f"
bitrate="$(exiftool -p '$AudioBitrate' "$script_dir"/"$newFile")"
#strips kpbs
bitrate=${bitrate% *}
echo ":BiTRATE:2 is :: $bitrate"
mid3v2 -a "$artist" "$script_dir"/"$newFile"
mid3v2 -A "$album" "$script_dir"/"$newFile"
mid3v2 -t "$title" "$script_dir"/"$newFile"
mid3v2 -g "$genre" "$script_dir"/"$newFile"
if [[ -n "$artist" && -n "$album" ]] ; then
{
mkdir -p "$move_new"
mkdir -p "$copy_new"
cp -vr "$script_dir"/"$newFile" "$copy_new"
mv -vf "$script_dir"/"$newFile" "$move_new"
}
else
{
mkdir -p "$NoTags"
mv -vf "$script_dir"/"$newFile" "$NoTags"
}
fi
} #no resampling needed goes here
elif [[ -n "$artist" && -n "$album" ]] ; then
{
mkdir -p "$move_new"
mkdir -p "$copy_new"
cp -vr "$f" "$copy_new"
mv -vf "$f" "$move_new"
}
else
{
mkdir -p "$NoTags"
mv -vf "$f" "$NoTags"
}
fi
unset album
unset atrist
unset title
done <<<"$(find "$working_dir" -type f -iname "*.mp3" -o -iname "*.flac" )"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.