I've created a开发者_JS百科 simple Bash script that should create symlinks in /usr/local/{etc,lib,include...} from an inputted directory path
#!/bin/sh
input="$1"
for subdir in "etc include bin lib man share sbin"; do
dir=$input/$subdir
if [ -e $dir ] && [ -d $dir ]; then
for file in $dir/*; do
ln -s $file /usr/local/$subdir
done
fi
done
The error i'm getting is:
user@comp:/usr/local# ./update-locallinks /usr/local/test/
[: 6: /usr/local/test/etc: unexpected operator
and this is what /usr/local/test/ looks like:
user@comp:/usr/local# ls /usr/local/test/
bin
etc
include
lib
Always protect your bash variables with double quotes in test expressions:
if [ -e "$dir" ] && [ -d "$dir" ]; then
for subdir in "etc include bin lib man share sbin"; do
Why the quotes? Change that to:
for subdir in etc include bin lib man share sbin; do
otherwise $dir
will contain etc include bin ...
on the first (and only) iteration.
精彩评论