Jump to content
Ang3lo

Find e espaços

Recommended Posts

Ang3lo

Boa tarde a todos,

Gostaria de saber se alguém me podia ajudar no seguinte, tenho de usar o comando find para verificar se existe

uma pasta com um determinado nome. Mas o problema é que quando o nome tem espaço o comando find diz

que a pasta na existe. Alguém sabe como se pode resolver este problema, para casos de pastas com nomes tipo "Meus Filmes"

Obrigado

Share this post


Link to post
Share on other sites
KTachyon

Tens que fazer escape ao espaço:

Meus\ Filmes


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Mas eu vou receber o nome por input na script, como posso colocar a \ no input?

Share this post


Link to post
Share on other sites
KTachyon

Podes sempre meter o path entre "". Funciona da mesma forma.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Testei na linha de comandos e funcionou perfeitamente, mas na minha script não funciona.

read opcao

artista=$opcao
echo $artista
if [ "$artista" != "fim" ] 
   then if( find /media/Angelo/Ang3lo/Musica/'$artista' -type d 2> Erros )

Sabes o que estou a fazer mal?

Obrigado

Share this post


Link to post
Share on other sites
KTachyon

Tens que colocar o path entre aspas:

find "path/to/destiny/$artista"


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Obrigado já funciona perfeitamente ;)

Agora estou a ter é problema ao ler do ficheiro porque ao apanhar espaços volta a dar erro,

ja tentei as " " mas sem sucesso.

for valor in $(cat /home/angelo/Desktop/lista) do .....

Conteúdo da lista é

/media/Angelo/Ang3lo/Musica/Dance Power 17 (2009)/CD1/In The Air.mp3

/media/Angelo/Ang3lo/Musica/CD2/Amor/10.mp3

No segundo caso funciona no primeiro dá sempre erro.

Sabes como posso contornar este problema?

Obrigado

Share this post


Link to post
Share on other sites
KTachyon

Depende de como estiveres a utilizar o path. Sempre que estiveres a executar um comando que utilize o path, só tens que rodear esse path com " ". Assim de repente não me recordo de nenhuma situação em que isso não funcione, mas pode ser que esteja enganado. Só preciso é de saber o que estás a tentar fazer com esse path.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

O que estou a tentar fazer com esse path é tocar com o mplayer, já testei com as "" na linha de comando e funciona mas com este codigo é que não dá. Aqui esta a script completa.

#!/bin/bash

for valor in $(cat /home/angelo/Desktop/playlist) 

do

mplayer "$valor"

done

exit

Obrigado

Share this post


Link to post
Share on other sites
KTachyon

Em vez de:

mplayer "$valor"

faz:

echo "$valor"


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Obtenho este resultado

/media/Angelo/Ang3lo/Musica/Dance

Power

17

(2009)/CD1/In

The

Air.mp3

/media/Angelo/Ang3lo/Musica/CD2/Amor/10.mp3

Onde tem os espaços ele parte a informação :\

Share this post


Link to post
Share on other sites
KTachyon

Era aí que eu queria chegar ;)

Tenta da seguinte forma:

cat "/home/angelo/Desktop/playlist" | while read line
do
mplayer "$line"
done


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Agora já toca a musica  ;) B)

Mas (há sempre uma mas  :cheesygrin: ) é que no código que te tinha anteriormente ao clicar no ENTER

o mplayer trocava de musica e agora não troca tenho de esperar que esta acabe para passar à seguinte :\

Share this post


Link to post
Share on other sites
KTachyon

Convém é imprimires uma linha vazia no final da playlist, senão a script não vai ler a última linha, penso eu,


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
Ang3lo

Afinal só toca a primeira linha mesmo, mal acaba a musica não toca mais

Aparece esta mensagem

AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video

A: 247.4 (04:07.4) of 247.0 (04:07.0)  1.1% 
Assertion 'm' failed at pulse/thread-mainloop.c:172, function pa_threaded_mainloop_lock(). Aborting.


MPlayer interrupted by signal 6 in module: unknown
- MPlayer crashed. This shouldn't happen.
  It can be a bug in the MPlayer code _or_ in your drivers _or_ in your
  gcc version. If you think it's MPlayer's fault, please read
  DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and
  won't help unless you provide this information when reporting a possible bug.
[ This binary of MPlayer in Debian is currently compiled with
   '--enable-debug'; the debugging symbols are in the package
   'mplayer-dbg'.]

Share this post


Link to post
Share on other sites
Ang3lo

Bom dia,

Sabem se é possível adicionar as funções das teclas para cima e para baixo à minha script?

Para fazer o mesmo que na linha de comandos.

Obrigado

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.