cciemaple 发表于 2004-10-29 00:12:26

再问一个小问题

这个脚本

script1=$1
file1=$2

sed$script1 $file > /tmp/test

总是执行不了,不能重定向到/tmp/test

可是直接用
sed $1 $2 > /tmp/test就可以

为什么呢?THX各位的无私帮助

MichaelBibby 发表于 2004-10-29 13:57:07

Re: 再问一个小问题

script1=$1
file1=$2

sed$script1 $file > /tmp/test

总是执行不了,不能重定向到/tmp/test

可是直接用
sed $1 $2 > /tmp/test就可以

为什么呢?THX各位的无私帮助
$1和$2都是位置参数( positional parameter )

我测试了一下,没有问题呀

#!/bin/bash

file1=$1
file2=$2

echo "This is file1 : $file1"
echo "This is file2 : $file2"

echo $1
echo $2

执行:$ ./scriptname.sh 1 2
This is file1 : 1
This is file2 : 2
1
2

cciemaple 发表于 2004-10-30 06:13:20

可是重定向怎么也不能成功,不知道为什么啊

MichaelBibby 发表于 2004-10-30 08:56:57

把你完整的代码贴上来 :o

dannycat 发表于 2004-10-30 10:03:45

Re: 再问一个小问题

script1=$1
file1=$2

sed$script1 $file > /tmp/test

MichaelBibby 发表于 2004-10-30 10:08:56

Re: 再问一个小问题

script1=$1
file1=$2

sed$script1 $file > /tmp/test
:oops: 是我太粗心了 :oops:
页: [1]
查看完整版本: 再问一个小问题