agkerr3
May 20th, 2009, 04:00 PM
I'm a bit new to bash scripting and have run into a problem with a "do" loop. I have a script that allows users to restore archived projects. The script asks for some basic input, uses those variables to find the project folder, and creates a ro symlink back to the archive.
The problem comes when users enter data that matches multiple archived directories - it was causing the script to error out - so I am trying to put in a do loop that will create a separate link for each directory that it finds. If $FULLNAME has multiple values, it attempts to make one link with the multiple values all mashed together, i.e.
+ ln -s '/mnt/e1.0/archive/05000/05153.00 XXX College
05153.01 - XXX Addition' '/mnt/project2/jobs2/05000/A_05153.00 XXX College 05153.01 - XXX Addition'
produces a link
/mnt/project2/jobs2/05000/A_05153.00 Walsh College?05153.01 - Walsh Addition
instead of two links like:
/mnt/project2/jobs2/05000/A_05153.00 Walsh College
/mnt/project2/jobs2/05000A_05153.01 - Walsh Addition
I think this is a quoting issue but I can't suss out what I'm doing wrong. Script follows:
#! /bin/bash
# a script for creating symlinks from archived projects
echo "Enter project directory (i.e. 03000)"
read -e YEAR
echo "Enter project number i.e.03155.01"
read -e PROJECT
sudo chmod 755 -R "/mnt/e1.0/archive/$YEAR/$PROJECT"*
sudo chown root:root -R "/mnt/e1.0/archive/$YEAR/$PROJECT"*
FULLNAME=`ls "/mnt/e1.0/archive/$YEAR" | grep $PROJECT`
for i in "$FULLNAME"
do
ln -s "/mnt/e1.0/archive/$YEAR/$i" "/mnt/project2/jobs2/$YEAR/A_$i"
done
exit $?
The problem comes when users enter data that matches multiple archived directories - it was causing the script to error out - so I am trying to put in a do loop that will create a separate link for each directory that it finds. If $FULLNAME has multiple values, it attempts to make one link with the multiple values all mashed together, i.e.
+ ln -s '/mnt/e1.0/archive/05000/05153.00 XXX College
05153.01 - XXX Addition' '/mnt/project2/jobs2/05000/A_05153.00 XXX College 05153.01 - XXX Addition'
produces a link
/mnt/project2/jobs2/05000/A_05153.00 Walsh College?05153.01 - Walsh Addition
instead of two links like:
/mnt/project2/jobs2/05000/A_05153.00 Walsh College
/mnt/project2/jobs2/05000A_05153.01 - Walsh Addition
I think this is a quoting issue but I can't suss out what I'm doing wrong. Script follows:
#! /bin/bash
# a script for creating symlinks from archived projects
echo "Enter project directory (i.e. 03000)"
read -e YEAR
echo "Enter project number i.e.03155.01"
read -e PROJECT
sudo chmod 755 -R "/mnt/e1.0/archive/$YEAR/$PROJECT"*
sudo chown root:root -R "/mnt/e1.0/archive/$YEAR/$PROJECT"*
FULLNAME=`ls "/mnt/e1.0/archive/$YEAR" | grep $PROJECT`
for i in "$FULLNAME"
do
ln -s "/mnt/e1.0/archive/$YEAR/$i" "/mnt/project2/jobs2/$YEAR/A_$i"
done
exit $?