0

Possible Duplicate:
Change directory with -d in shell script

I am trying to give the option to the users to run the script in a different directory. However when the script changes the directory, the mkdir does not work. I change the directory like this:

case $1 in
 "-d")
   PWD=$2;;
   *)
     ;;
esac

but when I run the script I get this error:

sasha@ubuntu:~/Desktop$ ./shellsc.sh -d /home/sasha/Downloads/
trigger took place in /home/sasha/Desktop
processing "1.sh.save.1" ...
./shellsc.sh: line 22: mkdir: command not found

here is the complete code:

#!/bin/bash
#File sorter
set -e    # Abort in case of error
START=$(date +"%T")
SAVEIFS=$IFS
case $1 in
    "-d")
      PWD=$2;;
    *)
      ;;
esac
echo "trigger took place in $PWD"
for i in *; do
  echo "processing \"$i\" ..."
  case $i in
    *.zip)
      [ -d archive ] || mkdir archive
      mkdir "archive/${i%.*}"
      unzip -d "archive/${i%.*}" "./$i"
      echo -e "\"$i\" extracted in $PWD/archive/${i%.*}" >> report.txt;;
    *.*)
      mkdir -p "${i##*.}"
      mv -- "$i" "${i##*.}/"
      echo -e "\"$i\" moved to $PWD/${i##*.}" >> report.txt;;
    *)
      tmp=$(TMPDIR=. mktemp -d)
      mv -- "$i" "$tmp/"
      mv -- "$tmp" "$i";;
  esac
done
echo "Done in $SECONDS seconds!"
END=$(date +"%T")
echo "Start time: $START" >> report.txt
echo "End time: $END" >> report.txt
0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.