我不会撒谎。这是为了一个任务。我被困住了,这有点令人沮丧,所以我来到这里作为我的最后手段,所以请帮助我。
因此,我需要编写一个脚本来查找和打印,如果路径是相对路径或绝对路径。我陷入了教授希望我做命令行替代的最后一部分,我不知道该怎么做。这是我到目前为止所拥有的。
if [ "$#" -ne 1 ]; then
echo 1>&2 "$0: please insert one valid file name;found $# ($*) "
echo 1>&2 "Usage: $0 [Filename..]"
exit 2
fi
if [ -z "$1" ] ; then
echo 1>&2 "$0: file name cannot be empty; found $# ($*) "
echo 1>&2 "Usage: $0 [filename...] "
exit 2
fi
if [ ! -L "$1" ] ; then
echo 1>&2 "$0: The pathname '$1' is not a symlink"
echo 1>&2 "Usage: '$0' [symlink] "
exit 2
fi
a=ls "$1" | awk '{ print $NF }'
if [ -z "$a" ] ; then
echo 1>&2 "$0: Pathname is empty "
exit 3
fi
type=$(a)
case "$b" in
/* ) type='an Absolute Pathname' ;;
* ) type='a Relative Pathname in the current directory' ;; # the "default" match
echo "pathname'$a' is $type"
esac
如果问题不够清楚,请提出任何问题。谢谢
答案1
剧本还远没有准备好,但你现在已经走在正确的轨道上了。
if [ "$#" -ne 1 ]; then
echo 1>&2 "$0: please insert one valid file name;found $# ($*) "
echo 1>&2 "Usage: $0 [Filename..]"
exit 2
fi
if [ -z "$1" ] ; then
echo 1>&2 "$0: file name cannot be empty; found $# ($*) "
echo 1>&2 "Usage: $0 [filename...] "
exit 2
fi
if [ ! -L "$1" ] ; then
echo 1>&2 "$0: The pathname '$1' is not a symlink"
echo 1>&2 "Usage: '$0' [symlink] "
exit 2
fi
a=$(ls -l "$1" | awk '{ print $NF }')
if [ -z "$a" ] ; then
echo 1>&2 "$0: A Really Good Error Message."
exit 3
fi
# type=$a
case "$a" in
/*) type='an Absolute Pathname' ;;
*) type='a Relative Pathname in the current directory' ;; # the "default" match
esac
echo "pathname'$a' is $type"