script-array.sh
来自「Shall高级编程」· Shell 代码 · 共 29 行
SH
29 行
#!/bin/bash# script-array.sh: Loads this script into an array.# Inspired by an e-mail from Chris Martin (thanks!).script_contents=( $(cat "$0") ) # Stores contents of this script ($0) #+ in an array.for element in $(seq 0 $((${#script_contents[@]} - 1))) do # ${#script_contents[@]} #+ gives number of elements in the array. # # Question: # Why is seq 0 necessary? # Try changing it to seq 1. echo -n "${script_contents[$element]}" # List each field of this script on a single line. echo -n " -- " # Use " -- " as a field separator.doneechoexit 0# Exercise:# --------# Modify this script so it lists itself#+ in its original format,#+ complete with whitespace, line breaks, etc.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?