Como posso suprimir essas mensagens de erro?

0

Estou usando o macOS 10.12.1 e o bash 3.2.57 (1) -release. Esse script faz exatamente o que eu quero, exceto por uma coisa: não quero que todas as mensagens "Nenhum arquivo ou diretório" sejam impressas. Aqui está o script:

#!/bin/bash
#set -x
cd "/volumes/Mac HD Ext/iTunes/Audiobooks"
pwd
for dir in *
do
#echo "$dir"
[ "$(ls ./"${dir}"/*.m4a)" ] && cd "${dir}" || continue
#ls *.m4a
pwd

for nameext in *.m4a
do  
    #echo $nameext
    name=${nameext%.*} # name has the .m4a removed
    #echo ${name}
    newnameext=${name}.m4b # Add .m4b onto name
    #echo ${newnameext}
    #echo ${nameext}-${newnameext}
    #mv "${nameext}" "${newnameext}"  # Activate when ready
    echo "${nameext}" "${newnameext}"

    echo
done
cd ..     # Move back to Audiobooks directory
done
exit

e aqui faz parte da saída:

ls: ./Eugenia Cheng/*.m4a: No such file or directory
ls: ./Eustace Mullins/*.m4a: No such file or directory
ls: ./F. Scott Fitzgerald/*.m4a: No such file or directory
ls: ./Frank H. T. Rhodes/*.m4a: No such file or directory
/volumes/Mac HD Ext/iTunes/Audiobooks/Frans de Waal
Our Inner Ape_ A Leading Primatologist Explains Why We Are Who We Are.m4a Our Inner Ape_ A Leading Primatologist Explains Why We Are Who We Are.m4b

/volumes/Mac HD Ext/iTunes/Audiobooks/Frans de Waal_Sean Runnette
Are We Smart Enough to Know How Smart Animals Are_ - Part 01.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 01.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 02.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 02.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 03.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 03.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 04.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 04.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 05.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 05.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 06.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 06.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 07.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 07.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 08.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 08.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 09.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 09.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 10.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 10.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 11.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 11.m4b

Are We Smart Enough to Know How Smart Animals Are_ - Part 12.m4a Are We Smart Enough to Know How Smart Animals Are_ - Part 12.m4b

ls: ./Frederick Forsyth/*.m4a: No such file or directory
ls: ./Gabor Boritt/*.m4a: No such file or directory
ls: ./Gaius Julius Caesar/*.m4a: No such file or directory
ls: ./Genevieve von Petzinger/*.m4a: No such file or directory
    
por grok12 06.12.2016 / 01:15

1 resposta

1

Você pode redirecionar o erro padrão de ls para o intervalo de bits, ou seja, ls blah 2> /dev/null . Devo salientar de passagem que usar find pode ser uma solução mais elegante para esse caso de uso e evita esse problema por definição.

    
por 06.12.2016 / 04:39