尝试在ubuntu中回显变量bash脚本获取null

时间:2017-05-18 08:04:00

标签: linux terminal null echo

我试图理解为什么同样的命令

echo "$LOGNAME, $PWD, $OSTYPE, $BASH"

在同一目录中直接键入终端vs bash脚本时获得不同的输出。如图所示,bash脚本将OSTYPE和BASH打印为null。enter image description here

我的bash脚本是:

#!/bin/bash
#my second script :)
clear;
while true
do
    echo "\nenter\n1 to login username, pwd, os type and bash type\n2 to date and time and calendar\n3 to pwd and ls\n4 to archiving your home directory\n5 to exit"
    read input;
    case $input in
        "1")echo "$LOGNAME, $PWD, $OSTYPE, $BASH";;
        "2")echo "date and time:$(date -R)\ncal:\n$(cal)";;
        "3")echo "$(pwd)\n$(ls -l)";;
        "4")echo "trying to archive";tar -czf archive.tar.gz *;;
        "5")echo "goodbye";exit 0;;
        "*")echo "try again";clear;;
    esac
done

案例1)行输出:nader,/ home / nader / Desktop / del,linux-gnu,/ bin / bash  如果在终端中单独输入。并获取nader,/ home / nader / Desktop / del,如果在脚本文件中执行。

0 个答案:

没有答案