这个脚本在Linux中工作吗?

这个脚本在Linux中工作吗?,linux,shell,kernel,Linux,Shell,Kernel,这在Linux中是否可以正常工作?我正在尝试创建一个make_symlinks.sh文件,所以我必须检查Darwin(它已经可以工作了),但是由于我没有Linux机器可以测试,我不知道这个脚本是否可以在Linux中工作 那么,这有用吗?谢谢你的帮助 脚本的修改版本提供: kernel=`uname -s` # Current Kernel name user=`whoami` # Current Unix username time=`date +%H:%M`

这在Linux中是否可以正常工作?我正在尝试创建一个
make_symlinks.sh
文件,所以我必须检查Darwin(它已经可以工作了),但是由于我没有Linux机器可以测试,我不知道这个脚本是否可以在Linux中工作


那么,这有用吗?谢谢你的帮助

脚本的修改版本提供:

kernel=`uname -s`        # Current Kernel name
user=`whoami`            # Current Unix username
time=`date +%H:%M`       # Output current time
current_dir=$(pwd)       # Shell's current location
script_dir=$(dirname $0) # This script's current location

# This if statement is to know the correct location of the script, if the
# shell's location is the same as the script's location
if [ $script_dir = '.' ]; then
    script_dir="$current_dir"
fi

if [ $kernel == 'Linux' ]; then
    # Making symlinks to Vim files, add yours as you need
    echo 'Making symlinks to Vim files'
    ln -s -v $script_dir/vim /home/$user/.vim
    ln -s -v $script_dir/vim/vimrc /home/$user/.vimrc
    ln -s -v $script_dir/vim/gvimrc /home/$user/.gvimrc
    echo "Done at [$time]...\n"

    # Making symlinks to Zsh files, add yours as you need
    echo 'Making symlinks to Zsh files'
    ln -s -v $script_dir/zsh /home/$user/.zsh
    ln -s -v $script_dir/zsh/zshrc /home/$user/.zshrc
    echo "Done at [$time]...\n"

    # Making symlinks to Git files, add yours as you need
    echo 'Making symlinks to Git files'
    ln -s -v $script_dir/git/gitconfig /home/$user/.gitconfig
    ln -s -v $script_dir/git/gitmessage.txt /home/$user/.gitmessage.txt
    echo "Done at [$time]...\n"
fi

修改脚本:

kernel=Linux
user=david
time=23:04
current_dir=/home/david/SO/Test
script_dir=/home/david/SO/Test
您的
ln
命令可以工作:

kernel=`uname -s`        # Current Kernel name
user=`whoami`            # Current Unix username
time=`date +%H:%M`       # Output current time
current_dir=$(pwd)       # Shell's current location
script_dir=$(dirname $0) # This script's current location

# This if statement is to know the correct location of the script, if     the
# shell's location is the same as the script's location
if [ $script_dir = '.' ]; then
    script_dir="$current_dir"
fi

if [ $kernel == 'Linux' ]; then
  echo "kernel=$kernel" 
  echo "user=$user" 
  echo "time=$time"
  echo "current_dir=$current_dir" 
  echo "script_dir=$script_dir" 
fi

哇,检查它并告诉我它是否有效真的有那么难吗?为什么不喜欢?至少告诉我哪里出了问题。我在问那些拥有Linux的人,他们当然知道他们在说什么。我们不是来为你远程测试你的代码的。访问linux设备并试用。我在Mac电脑上,上次安装Ubuntu时无法访问互联网/太好了,这就是我需要知道的。那么,这将生成到正确位置的正确符号链接,对吗?你可以把它换成你自己的点文件的位置,来测试它。太棒了!只是想确认一下,这些都是Linux中正确的文件名,对吗?@Eduan,你的点文件名似乎没问题。我看不出它们有什么理由在达尔文和Linux之间使用不同的名称。太棒了!谢谢你的帮助!:)
NAME
       ln - make links between files

SYNOPSIS
       ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
       ln [OPTION]... TARGET                  (2nd form)
       ln [OPTION]... TARGET... DIRECTORY     (3rd form)
       ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
#[...]
       -s, --symbolic
              make symbolic links instead of hard links

       -v, --verbose
              print name of each linked file