能否不用迴圈印出 1 至 1000 的數字?
 
   
Script 1-7
# ----------------------------------------------------
# Script 1-7:  print 1 to 1000,  C version  with Loop
# ---------------------------------------------------- 
#include <stdio.h> main(){ int i; for (i=1; i<=1000; i++){ printf ("%d\n", i); } }
 
   
Script 1-8
# -------------------------------------------------------
# Script 1-8:  print 1 to 1000, Shell Script v1 with Loop
# ------------------------------------------------------- 
count=1 while [ $count -le 1000 ] do echo $count count=`expr $count + 1` done
 
   
Script 1-9
# ---------------------------------------------------------
# Script 1-9:  print  1 to 1000, Shell Script v2 Loopless
# 假設 testfile 是一個超過1000行的文字檔
# --------------------------------------------------------- 
head -1000 testfile | cat -n | cut -c1-6 #------------------------------------------------- #head -1000 testfile 這個指令將 testfile 的前1000行抓出來, #其次 cat -n 則在每一行之前打上行號, #而 cut -c1-6 則將行號(前六個字母)抓出來,就得到所要的數列。
 
   
Script 1-10

# -------------------------------------------------------- 
# Script 1-10:  print  1 to 1000, Shell Script v3 Loopless
# -------------------------------------------------------- 
head -1000 testfile | awk "{print NR}"