n=0 txtfile=`ifconfig |grep "ppp"|awk '{print $1}'` for x in $txtfile do array[$n]=$x n=$((n+1) done 如上,现在想实现将txtfile的值存入一个数组中。不过视乎不行。指向的时候 array[$n]还是为 array[$n] 不会变成 array[0] array[1]..... 请教一下大家。如何实现这样的赋值
看到
1.# **|uniq -c 1 1 1 9 1 36 1 69 1 76 2. 把这些值付给数组,然后调用数组元素运算。 这样的东西在shell写如何写 这个在perl用hash比较容易,在shell中不知道如何做了 [ 本帖最后由 huanghaojie 于 2009-2-18 15:04 编辑 ]
[color="#000000"]$ A=(a b c def)EybLinux联盟 EybLinux联盟 ==================================================EybLinux联盟 $ echo ${A[@]} //取全部元素EybLinux联盟 a b c defEybLinux联盟 EybLinux联盟 =================================================EybLinux联盟 EybLinux联盟 $ echo ${A[0]} //取第一个元素EybLinux联盟 aEybLinux联盟 EybLinux联盟 =================================================EybLinux联...
shell数组 Bash中还可以使用数组变量,其赋值有两种: (1) name = (value1 ... valuen) 此时下标从0开始 (2) name[index] = value 数组下标的范围没有任何限制,同时也不必使用连续的分量. -------------------------------------------------------------------------------- $ A=(a b c def) ================================================== $ echo ${A[@]} //取全部元素 a b c def =========================================...
#!/bin/bash A=(a b c def) echo ${A[@]} //取全部元素 echo ${A[0]} //取第一个元素 echo ${#A[@]} //取得元素3的长度 echo ${#A} //取得元素3的长度 echo ${#A[3]} //取得元素3的长度 A[3]=ghb //将第三个元素重新赋值 echo ${A[@]} $ echo ${A[@]} 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/11765/showart_312287.html
请教各位高手:
有文件tmp.txt:
jhgdhfgjhdfjkg => hdfghkjdhfg
hfghdjfhgkjdh => hfgjhdkjfhgkj
我欲将$1即第一个域中的字符循环读入数组a中
然后 echo "$a" 循环显示出来
用while read line
do
for i;do
a=awk '{print $1}'
echo "$a"
done
done<
#!/bin/sh -f cat $1|while read LINE do echo $LINE done #!/bin/sh -f cat $argv【1】|while read LINE do echo $LINE done 为什么前者能正确执行,后者却不能?