Creating a symbolic link in a bash script in a different folder

My bash script is getting two arguments with folders (that exist and everything).

Inside the first one I want to create a link to the second

Suppose I have the folders /home/matt/a and /home/matt/b, I call the script like this :

/home/matt # ./my_script ./a ./b

I want to see a symbolic link inside a that points to b

And of course, just doing

ln -s $2 $1/link

in the script does not work... (it will create a link that looks for a ./b inside a)

This is just a very simple example, I am looking for a script that will be generic enough to take different arguments (absolute or relative path...etc...)


Give this a try:

ln -s "$(readlink -e "$2")" "$1/link"

if you have readlink .

Or perhaps this variation on the answer by larsmans:

cd "$2"
dir=$(pwd)
cd -
ln -s "$dir" "$1/link"

#!/bin/sh
cd $2
ln -s "`pwd`" $1/link

这是另一个可爱的单线:

ln -s `cd `dirname $2`; pwd`/`basename $2` $1/link
链接地址: http://www.djcxy.com/p/48236.html

上一篇: 如何在关系数据库中建立自定义类型的模型?

下一篇: 在不同文件夹中的bash脚本中创建符号链接