I know that it works for alias instructions in the file .bashrc. However, a shell script ln_hook:
#!/bin/sh
#filename: ln_hook
## http://stackoverflow.com/questions/3648819/how-to-make-symbolic-link-with-cygwin-in-windows-7
## https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
## https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
# export CYGWIN="winsymlinks" # ln -s: The shortcut style symlinks with file extension '.lnk'
# export CYGWIN="winsymlinks:native" # ln -s: plain text file
ln_hook(){
if [[ "-s" == "$1" ]]; then
cmd /C mklink /H "$(cygpath -aw "$3")" "`cygpath -aw "$2"`"
else
echo -e "\033[32m >> $* \033[0m"
ln "$*"
fi
}
alias ln='ln_hook'
type ln
(type ln)
# cannot propagate to another shell script
./test_ln
$(dirname $0)/test_ln
## . ./ln_hook
## type ln
and, another shell script:
#!/bin/sh
#filename: test_ln
type ln
Then run . ./ln_hook
, output:
ln_hook
ln 是 `ln_hook' 的别名
ln 是 `ln_hook' 的别名
ln 是 /usr/bin/ln
ln 是 /usr/bin/ln
Is there a workaround to make the alias effective when running other scripts?