0

In the code below I was expecting an output like this:

Transmission_Downloads/The.Last.Man.On.Earth.S02E04.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt
Transmission_Downloads/Fargo.S02E01.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt
Transmission_Downloads/Nightwish - Showtime Storytime (2013) 1080p 5.1/SEMEAR.txt

But what I do got was this

Transmission_Downloads/The.Last.Man.On.Earth.S02E04.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt
Transmission_Downloads/Fargo.S02E01.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt
Transmission_Downloads/Nightwish
-
Showtime
Storytime
(2013)
1080p
5.1/SEMEAR.txt

What should I do for my shell script parse blank spaces on file and folder names correctly? Thanks!

#!/bin/bash

#opcao -s nao mostra o texto na tela
echo "Digite sua senha"
read -s answer

root_folder="/home/pi/"
user="pi"
server="*****"
local_folder="/home/dellcloud2"

#Colocar aqui os paths dos arquivos que deseja puxar
array=(
    "Transmission_Downloads/The.Last.Man.On.Earth.S02E04.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt"
    "Transmission_Downloads/Fargo.S02E01.HDTV.x264-KILLERS[ettv]/Torrent-Downloaded-from-ExtraTorrent.cc.txt"
    "Transmission_Downloads/Nightwish - Showtime Storytime (2013) 1080p 5.1/SEMEAR.txt"
)
for i in ${array[@]}; do
    #sshpass -p $answer rsync -aP $user@$server:$root_folder$i $local_folder
    echo $i
done
1
  • Escape variables when you use them. All the time. "${array[@]}", "$i", etc. Commented Oct 23, 2015 at 18:42

1 Answer 1

2

You need to use "${array[@]}" to preserve white space. The quotes around the array plus the wildcard @ together enable this.

This also works with positional parameters, i.e. "$@" gives you an array of the command line arguments, properly quoted as they were given.

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

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.