あなたが allcommands.sh で行っていることは次のとおりだと思います:
command1.sh
command2.sh
で置き換えるだけです
command1.sh | sed "s/^/[command1] /"
command2.sh | sed "s/^/[command2] /"
allcommands.sh の最小限の例 :
#!/bin/bash
for i in command{1,2}.sh; do
./"$i" | sed 's/^/['"${i%.sh}"'] /'
done
command1.sh で と command2.sh 実行可能で、同じディレクトリに echo だけ 必要な文字列を入力すると、シェル出力が得られます:
$ ./command1.sh
file exists
file moved
$ ./command2.sh
file copied
file emptied
$ ./allcommands.sh
[command1] file exists
[command1] file moved
[command2] file copied
[command2] file emptied
クイック sed 内訳
sed 's/^/['"${i%.sh}"'] /'
s/「正規表現パターンの一致と置換」モードに入ります^/「すべての行の先頭に一致する」という意味${i%.sh}シェルコンテキストで発生し、「$i」を意味します 、ただし接尾辞.shを取り除きます "['"${i%.sh}"'] /最初に[を出力します 、次に引用されたコンテキストを終了して$iを取得します シェルから変数を入力し、再入力して]で終了します とスペース。