0

我正在创建一个 shell 脚本。现在,如果标志为 ON,我想创建一个标志以在屏幕上打印脚本的输出,否则如果标志为 OFF,脚本将不会打印输出

谢谢

4

2 回答 2

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...
于 2013-09-13T07:43:58.297 回答
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")
$
于 2013-09-13T07:53:02.420 回答