shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] duvidas: find e $0


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] duvidas: find e $0
Date: Wed, 19 Mar 2008 14:26:50 -0300

Se vc precisa do nome do script que esta sendo executado tanto em uma
chamada externa quanto com o comando source, vc pode utilizar o array
BASH_SOURCE

man bash:
BASH_SOURCE - An array variable whose members are the source filenames
corresponding to the elements in the FUNCNAME array variable.

prompt> . example.sh asd
$BASH_SOURCE[0] = example.sh
$0 = bash
$1 = asd

prompt> ./example.sh asd
$BASH_SOURCE[0] = ./example.sh
$0 = ./example.sh
$1 = asd

prompt> cat example.sh
echo \$BASH_SOURCE\[0\] = ${BASH_SOURCE[0]}
echo \$0 = $0
echo \$1 = $1

Se vc precisa pegar o nome da função shell que vc esta executando, tem
que usar $FUNCNAME (como dito na dica acima)
 function doit(){
 echo \$BASH_SOURCE\[0\] = ${BASH_SOURCE[0]}
 echo \$0 = $0
 echo \$1 = $1
 echo \$FUNCNAME = $FUNCNAME
}

prompt> doit asd
$BASH_SOURCE[0] =
$0 = bash
$1 = asd
$FUNCNAME = doit


[]'s T
2008/3/19 André Saunite <address@hidden>:
>
>
>
>
>
>
> Oi Romano,
>
>  Para a primeira pergunta, se você não quer que o find procure em
>  subdiretórios pode usar o parâmetro -maxdepth igual a 1:
>
>  find <DIR> -maxdepth 1
>
>  Sobre a segunda pergunta, aparentemente o problema é utilizar o "."
> (source)
>  com $0, olha só:
>
>  $ cat teste
>  echo "PARAMETRO 0: $0"
>  $ ./teste
>  PARAMETRO 0: ./teste
>  $ . teste
>  PARAMETRO 0: -/bin/bash
>
>  Abs,
>  André Saunite
>
>
>  [As partes desta mensagem que não continham texto foram removidas]
>
>  



-- 
Tiago B Peczenyj
Linux User #405772

http://peczenyj.blogspot.com/
"what does not kill us makes us stronger"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]