📄 upperconv.sh
字号:
#!/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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -