⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex67.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bashdeclare -a colors#  All subsequent commands in this script will treat#+ the variable "colors" as an array.echo "Enter your favorite colors (separated from each other by a space)."read -a colors    # Enter at least 3 colors to demonstrate features below.#  Special option to 'read' command,#+ allowing assignment of elements in an array.echoelement_count=${#colors[@]}# Special syntax to extract number of elements in array.#     element_count=${#colors[*]} works also.##  The "@" variable allows word splitting within quotes#+ (extracts variables separated by whitespace).##  This corresponds to the behavior of "$@" and "$*"#+ in positional parameters. index=0while [ "$index" -lt "$element_count" ]do    # List all the elements in the array.  echo ${colors[$index]}  let "index = $index + 1"  # Or:  #    index+=1  # if running Bash, version 3.1 or later.done# Each array element listed on a separate line.# If this is not desired, use  echo -n "${colors[$index]} "## Doing it with a "for" loop instead:#   for i in "${colors[@]}"#   do#     echo "$i"#   done# (Thanks, S.C.)echo# Again, list all the elements in the array, but using a more elegant method.  echo ${colors[@]}          # echo ${colors[*]} also works.echo# The "unset" command deletes elements of an array, or entire array.unset colors[1]              # Remove 2nd element of array.                             # Same effect as   colors[1]=echo  ${colors[@]}           # List array again, missing 2nd element.unset colors                 # Delete entire array.                             #  unset colors[*] and                             #+ unset colors[@] also work.echo; echo -n "Colors gone."			   echo ${colors[@]}            # List array again, now empty.exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -