【发布时间】:2017-02-08 23:11:06
【问题描述】:
我正在编写一个 bash 脚本来 grep 文件,然后运行 perl 命令。我知道这些命令可以工作,因为我一直在使用它们,但我似乎无法让它们为 bash 脚本工作。我将不胜感激任何帮助。
当我输出 $1 等时,它有值,但是当我输出带有它们的 grep 命令时。我得到文件找不到或空格。
#! /bin/bash
usage()
{
echo "Usage: $0"
echo $'\a'Supply 4 arguments
echo $0 arg1 arg2 arg3 arg4
echo "1. search parameters for bookmarks"
echo "2. What file to grep"
echo "3. file to temporaly store results"
echo "4. what file to store the final version"
exit 1
}
main()
{
# if [ "$#" -lt "4" ]
# then
# usage
# else
echo "beginning grep"
grep -ir "$1" "$2" >> "$3"
echo "grep complete"
# echo "beginning perl command"
# perl -0ne 'print "$2\n$1\n" while (/a href=\"(.*?)\">(.*?)<\/a>/igs)' "$3" >> "$4"
# echo "perl command complete"
# echo "done"
# exit 1
# fi
}
main
echo $0
echo $1
echo $2
echo $3
echo $4
【问题讨论】: