sergioaraujo

 

if

Page history last edited by Anonymous 2 yrs ago

if

Testa condições para execução seletiva de ações ou comandos

 

# testa se o usuário é root
# != significa diferente
if [ "$USR" != "root" ]; then
echo '  Você não é root!'
fi
# testa se uma pasta existe
if [ ! -d ~/bin ]; then
mkdir ~/bin
fi
cd ~/bin
Obs: a exclamação é uma negação:
! -d  = (se não existe o diretório ~/bin)
Outro modo de testar se uma pasta existe
[ -d ~/bin ] || mkdir ~/bin ; cd ~/bin

Comments (0)

You don't have permission to comment on this page.