変数コマンドを使用したエコーループ

変数コマンドを使用したエコーループ

複数のリストがあり、リストに対していくつかのコマンドを実行したいと思います。リストが非常に長いので、コマンドを並列に実行したいので、nohup各項目に対してnohupコマンドを含むループを
試しましたが、うまくechoいきませcat another_list_of_names./tools。ループですが、'edはそれをstdoutに送ります。 nohupコマンドが並列に実行されるようにどのように設定しますか? (runを使用できますか?)catfor a in $(cat list_of_names)echofor b in $(cat another_list_of_names)
nohupecho

for a in $(cat list_of_names)
      do              
          ID=`echo $a`
          mkdir ${ID}
          echo " 
             nohup sh -c '
             for b in $(cat another_list_of_names)
               do 
                  ./tools $b $a >> ${ID}/output
               done' &
           "

      done

ベストアンサー1

あなたのコードをいくつか改善しました。

# This sort of loop is generally preferable to the one you had.
# This will handle spaces correctly.
while read a
do
   # There's no need for the extra 'echo'
   ID="$a"
   # Quote variables that may contain spaces
   mkdir "$ID"
   # This is a matter of taste, but I generally find heredocs to be more
   #  readable than long echo commands
   cat <<EOF
   nohup sh -c '
   while read b
   do
      # Quotation marks
      ./tools \$b $a >> "${ID}/output"
   done < another_list_of_names' &
EOF
done < list_of_names

おすすめ記事