Я использую macOS 10.12.1 и bash 3.2.57(1)-релиз. Этот bash-скрипт выполняет только то, что я хочу, за исключением одного: я не хочу, чтобы все эти сообщения "Нет такого файла или каталога" печатались. Вот сценарий:

#!/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

и вот часть вывода:

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

1 ответ1

1

Вы можете перенаправить стандартную ошибку ls в корзину битов, т.е. ls blah 2> /dev/null . Я должен мимоходом отметить, что использование find может быть более элегантным решением для этого варианта использования и позволяет избежать этой проблемы по определению.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .