upperconv.sh
来自「Shall高级编程」· Shell 代码 · 共 46 行
SH
46 行
#!/bin/bash# upperconv.sh# Converts a specified input file to uppercase.E_FILE_ACCESS=70E_WRONG_ARGS=71if [ ! -r "$1" ] # Is specified input file readable?then echo "Can't read from input file!" echo "Usage: $0 input-file output-file" exit $E_FILE_ACCESSfi # Will exit with same error #+ even if input file ($1) not specified (why?).if [ -z "$2" ]then echo "Need to specify output file." echo "Usage: $0 input-file output-file" exit $E_WRONG_ARGSfiexec 4<&0exec < $1 # Will read from input file.exec 7>&1exec > $2 # Will write to output file. # Assumes output file writable (add check?).# ----------------------------------------------- cat - | tr a-z A-Z # Uppercase conversion.# ^^^^^ # Reads from stdin.# ^^^^^^^^^^ # Writes to stdout.# However, both stdin and stdout were redirected.# Note that the 'cat' can be omitted.# -----------------------------------------------exec 1>&7 7>&- # Restore stout.exec 0<&4 4<&- # Restore stdin.# After restoration, the following line prints to stdout as expected.echo "File \"$1\" written to \"$2\" as uppercase conversion."exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?