I'm trying to parse the variable A_DESTINATION (a directory) and only call out the words in between the /.../
case "$TR_TORRENT_INFO" in
*test1.com*)
A_DESTINATION=${A_DESTINATION}/Books/
;;
*test2.com*)
A_DESTINATION=${A_DESTINATION}/Movies/
;;
*test3.com*)
A_DESTINATION=${A_DESTINATION}/Music/
;;
*)
A_DESTINATION=${A_DESTINATION}/Miscellaneous/
;;
esac
test="$(egrep '\/([^/.]+)\/$' $A_DESTINATION)"
echo test
I've gotten a regex in my script but it's not returning the folder successfully (i.e. in this case, /Miscellaneous/) in my log. It's just displaying this:
+ A_DESTINATION=/mnt/sda1/Miscellaneous/
+ egrep \/([^/.]+)\/$ /mnt/sda1/Miscellaneous/
+ test=
+ echo test
test
What am I doing wrong? Thanks!
grep
works against files, not arguments. You're passing the var as an argument, and sogrep
is treating the argument it as a file to search. Also, why not usebasename
?echo "$A_DESTINATION" | egrep ...
or (if your shell supports here-strings)egrep ... <<< "$A_DESTINATION"
. OTOH if you omit the trailing/
in your assignments you could likely use the shell's built in parameter manipulation e.g."/${A_DESTINATION##*/}/"