LoginSignup
0
0

【bash】echoしつつコマンド実行する関数

Posted at

bash内にコマンドを記載する簡易版

#!/bin/bash
echommand () {
  echo Command: $@ >&2
  "$@"
  echo -------------------------------------
}

echommand aws s3 ls

コマンドを外部ファイルに記載し、結果をログファイルに出力するバージョン

#!/bin/bash
echo -n Please enter the log file name : 
read FILE
echommand () { 
  if [ "$1" = "echo" ]; then
    "$@" 2>&1 | tee -a $FILE
  else
    echo Command: $@ 2>&1 | tee -a $FILE
    "$@" 2>&1 | tee -a $FILE
  fi
  echo -------------------------------------
}
while read line
do
  echommand ${line}
done < "commandlist"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0