PDA

View Full Version : Why this command doesn't work (bash)



Yuzem
August 29th, 2007, 05:27 PM
I am making a script and I need to make a list of files to play in Banshee.
Banshee isn't the problem, the same happens with moc and totem.

The next command works:

totem "file1.mp3" "file2.mp3" "etc.mp3"

Then I get the list of files in the way I want with the following command from a directory with mp3 files:

find "$PWD" -maxdepth 1 -type f -iname '*.mp3' | sort | sed -e 's/^/"/' -e 's/$/"/' | tr '\n' ' '

If I paste the result of the previous command in front of "totem" It works, but if I put all together it doesn't work:

totem $(find "$PWD" -maxdepth 1 -type f -iname '*.mp3' | sort | sed -e 's/^/"/' -e 's/$/"/' | tr '\n' ' ')

Any ideas?

Nekiruhs
August 29th, 2007, 06:03 PM
Why do you have quotes around "$PWD", wouldn't it just be $PWD? Thats saying find the string "$PWD", not the value of PWD variable.

Ramses de Norre
August 29th, 2007, 06:06 PM
Why do you have quotes around "$PWD", wouldn't it just be $PWD? Thats saying find the string "$PWD", not the value of PWD variable.


~$ echo $PWD
/home/ramses
~$ echo "$PWD"
/home/ramses
~$ echo "\$PWD"
$PWD


If you've got spaces in your path you even must use quotes.

duff
August 29th, 2007, 08:30 PM
# cat script.sh
#!/bin/bash

function f {
echo "\$1: $1"
echo "\$2: $2"
echo "\$3: $3"
}

f "foo bar baz"
eval f "foo bar baz"

# ./script.sh
$1: foo bar baz
$2:
$3:
$1: foo
$2: bar
$3: baz

Yuzem
August 29th, 2007, 11:39 PM
mmm... I don't understand that code, I am a newbie :lolflag:

What I want is a working alternative to the following code:

totem $(find "$PWD" -maxdepth 1 -type f -iname '*.mp3' | sort | sed -e 's/^/"/' -e 's/$/"/' | tr '\n' ' ')

I don't know why it doesn't work but there must be a way to do that...
...or not?:(

duff
August 30th, 2007, 12:02 AM
mmm... I don't understand that code, I am a newbie :lolflag:

What I want is a working alternative to the following code:

totem $(find "$PWD" -maxdepth 1 -type f -iname '*.mp3' | sort | sed -e 's/^/"/' -e 's/$/"/' | tr '\n' ' ')

I don't know why it doesn't work but there must be a way to do that...
...or not?:(

then put "eval" before totem

Yuzem
August 30th, 2007, 12:57 AM
Wow!!! Thanks a lot!
That works perfectly.