unix⼀linux shell脚本

2025-03-11 09:06:34
推荐回答(3个)
回答1:

方法1:while read linedo for i in $line do echo $i donedone<1.txt 方法2:cat 1.txt|tr " " "\n"方法3:sed 's/ /\n/g' 1.txt

回答2:

$ cat > mtable
#!/bin/sh
#
#Script to test for loop
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
n=$1
for i in e f g 3 2 5
do
echo "$n * $i = `expr $i \* $n`"
done
还有一种是while命令
#!/bin/bashecho "输入一个数:"
read numi=e while [ $i e f g 3 2 5]
do echo "$num*$i=`expr $num \* $i`" i=`expr $i + 1`doneexit

回答3:

sed 's/ /\n/g' 1.txt
for i in `cat 1.txt`; do echo $i; done