シェルスクリプトを作成しています。ここで、フラグがオンの場合、スクリプトの出力を画面に出力するフラグを作成したいと考えています。そうでない場合、フラグがオフの場合、スクリプトは出力を出力しません。
ありがとう
シェルスクリプトを作成しています。ここで、フラグがオンの場合、スクリプトの出力を画面に出力するフラグを作成したいと考えています。そうでない場合、フラグがオフの場合、スクリプトは出力を出力しません。
ありがとう
以下のtest.shコード:
#!/bin/sh
while IFS= read -r line
do
cat "$line"
done < $1
試して:
$ ls
myflags testfile0 testfile1 testfile2 test.py test.sh
$ cat myflags
testfile0
testfile1
test.py
$ cat testfile0
some test
$ sh test.sh myflags
some test
#!/usr/bin/python
import sys
if sys.version_info[0] == 2:
sys.stdout.write("ls -l")
$
これはあなたのために働くかもしれません:
#!/bin/bash
# assuming your first argument is the printing flag
[[ "${1}" = "ON" ]] && OUTPUT="/dev/stdout" || OUTPUT="/dev/null"
# from now on:
echo "Something" > $OUTPUT
# will work as expected...