我正在创建一个shell脚本。现在,我想创建一个标志,如果标志为ON,则在屏幕上打印脚本输出,否则如果标志为OFF,脚本将不会打印输出
谢谢
答案 0 :(得分:0)
这可能对您有用:
#!/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...
答案 1 :(得分:0)
下面的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")
$