2017-09-10 15 views
1

私のスクリプトはたくさんのユーザがいるフォルダを入力します /parent/usr/home/fred fredのような特定のユーザに入ると、/ parentディレクトリにあるEXスクリプトを実行する必要があります /parentはどこでもかまいませんそして何という名前の私が知っているすべては、それがEXスクリプトは、私が持っているもの 現在のディレクトリにあるファイルの親ディレクトリにあるスクリプトをどのように実行しますか?

/フレッドにあるファイルを編集するEXを使用していますUSR 上だで、これまで

cd usr 
cd home 
FOLDERS=* 
L=".bash_login" 
P=".bash_profile" 
for f in $FOLDERS 
do 
cd "$f" 
if [ -f ".bash_login" ] 
then 
grep "/etc/runner" $L >/dev/null 
    if [ $? -eq 0 ] 
    then 
      #use swap ex 
      ex $L <replace.ex 
      echo "replaced" 
    else 
      ex $L <insert.ex 
      echo "inserted" 
      #use insert at end ex 
    fi; 
else 
    grep "/etc/runner" $P >/dev/null 
    if [ $? -eq 0 ] 
    then 
     # use swap ex 
     ex $P <replace.ex 
     echo "replaced" 
    else 
     ex $P <insert.ex 
     echo "inserted" 

    fi; 
fi; 
cd .. 
done 

編集: ただ、READLINK読ん行きます.exファイルでreadlinkを試してから、cdをフォルダーに挿入してください。

答えて

0

Readlinkが働いてくれてありがとう。

#!/bin/bash 
replace=$(readlink -f replace.ex) 
insert=$(readlink -f insert.ex) 
echo $insert 
echo $replace 
cd usr 
cd home 
FOLDERS=* 
L=".bash_login" 
P=".bash_profile" 

for f in $FOLDERS 
do 
cd "$f" 
if [ -f ".bash_login" ] 
then 
grep "/etc/runner" $L >/dev/null 
    if [ $? -eq 0 ] 
    then 
      #use swap ex 
      ex $L <$replace 
      echo "replaced" 
    else 
      ex $L <$insert 
      echo "inserted" 
      #use insert at end ex 
    fi; 
else 
    grep "/etc/runner" $P >/dev/null 
    if [ $? -eq 0 ] 
    then 
     # use swap ex 
     ex $P <$replace 
     echo "replaced" 
    else 
     ex $P <$insert 
     echo "inserted" 

    fi; 
fi; 
cd .. 
done 
関連する問題