0

I`m new to bash scripting and need some help with a strange problem.

Here is my lines of code:

#!/bin/ash -x  
echo  Variabel \$1='\t'$1  
TARGET_DIR=/volume1/video/Transcoded/  
echo "Variabel\$TARGET_DIR=$TARGET_DIR"  
fbname=$(basename "$1")  
echo  Variabel \$fbname=$fbname  
out="${fbname}""${TARGET_DIR}"  
echo  $out  
read -p "Press [Enter] key to start next Transcode..."  

This outputs:

Variabel $1=\t/volume1/video/Movies/Thor (2011)/Thor (2011).mkv  
Variabel$TARGET_DIR=/volume1/video/Transcoded/  
Variabel $fbname=Thor (2011).mkv  
/volume1/video/Transcoded/  
Press [Enter] key to start next Transcode... 

in the the last echo $out shoulde be path and file name combined.. but it is broken. what could be wrong?

Thanks for any anwer:)

4
  • 1
    ash is not bash, not that that appears to be relevant to what you've used so far. Commented Apr 15, 2012 at 8:54
  • you are correct it is on a Synology wich has buid inn ash... Commented Apr 15, 2012 at 15:43
  • 1
    please edit your question to include your required output. Also I don't get why you want the filename to precede a pathname? When I used "xxx/Thor (2011).mkv" as the value for $1, my output was Thor (2011).mkv/volume1/video/Transcoded/, which is what I would have predicted. Good luck! Commented Apr 15, 2012 at 17:45
  • It works for me too, and identically in both dash and bash. The irreproducible results are probably a result of something funny in $1; please rewrite with $1 replaced by a variable set within the script. Commented Apr 15, 2012 at 22:14

2 Answers 2

1

It looks to me like either $1 or some of the lines of the script end with a carriage return (sometimes written \r) -- this character is generally invisible, but can cause weird behavior and output. For instance, if we start with TARGET_DIR="/volume1/video/Transcoded/" and fbname=$'Thor (2011).mkv\r' (note: $'...' is bash notation for a string with escape sequences like \r interpreted), then you'll wind up with out=$'Thor (2011).mkv\r/volume1/video/Transcoded/', and when you echo $out, it prints:

Thor (2011).mkv
/volume1/video/Transcoded/

... with the second "line" printed on top of the first, so you never actually see the first part.

Stray carriage returns are usually a result of using DOS/Windows text editors -- don't use them for unix text files (incl. scripts). To remove them, see the previous questions here and here.

BTW, I second @shellter's confusion about why the filename is before the path...

Sign up to request clarification or add additional context in comments.

Comments

1

try this:

out="${fbname}${TARGET_DIR}"  
echo  $out  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.