摘要:
#!/bin/bash# reassign-stdout.shLOGFILE=logfile.txtexec 6>&1 # Link file descriptor #6 with stdout. # Saves stdout.exec > $LOGFILE # stdout replaced with file "logfile.txt".# ----------------------------------------------------------- ## All output from commands in this block sent 阅读全文
摘要:
#!/bin/bash# Redirecting stdin using 'exec'.#exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin.exec 0< data-file # stdin replaced by file "data-file"read a1 # Reads first line of file "data-file".read a2 # Reads second line of file "data-file.&q 阅读全文
摘要:
#!/bin/bash# Declare arraydeclare -a ARRAY# Link filedescriptor 10 with stdinexec 10<&0# stdin replaced with a file supplied as a first argumentexec < $1let count=0while read LINE; do ARRAY[$count]=$LINE ((count++))doneecho Number of elements: ${#ARRAY[@]}# echo array's contentecho ${A 阅读全文
摘要:
#!/bin/bash#Declare array with 4 elementsARRAY=( 'Debian Linux' 'Redhat Linux' Ubuntu Linux )# get number of elements in the arrayELEMENTS=${#ARRAY[@]}# echo each element in array # for loopfor (( i=0;i<$ELEMENTS;i++)); do echo ${ARRAY[${i}]}done 阅读全文
摘要:
#!/bin/bashecho -e "Hi, please type the word: \c "read wordecho "The word you entered is: $word"echo -e "Can you please enter two words? "read word1 word2echo "Here is your input: \"$word1\" \"$word2\""echo -e "How do you feel about ba 阅读全文