on linux a bash script can be executed by a simply click. on osx $pwd seems messed ie files not found in: cp filea ../blbl/blbl/ when not executed alike ./script but with a click as *.command or *.sh
someone could fix my work below? i calculated 2 min and already spent moren than an hour on such ...:-(
Thanks
----------
tell application "Finder" to set f to POSIX path of ((container of (path to me)) as alias)
tell application "Terminal"
activate
set t to (make new terminal)
tell t
tell (make new session at the end of sessions)
do shell script "echo
echo Copying files
echo
sleep 5
cp -r -v &f&/a.txt &f&/../bl/blala/a.txt
exit 0"
end tell
end tell
end tell
8 replies to this topic
#1
Posted 18 July 2011 - 11:29 AM
#2
Posted 19 July 2011 - 02:47 AM
What I use in my Bash .command files is:
#!/bin/bash
WorkDir=$(cd -P -- $(dirname -- "$0") && pwd -P)
cd "${WorkDir}"
blah blah blah (rest of script)
Probably better ways of doing it but works great.
#!/bin/bash
WorkDir=$(cd -P -- $(dirname -- "$0") && pwd -P)
cd "${WorkDir}"
blah blah blah (rest of script)
Probably better ways of doing it but works great.
#3
Posted 19 July 2011 - 07:12 AM
Yes simplest to only use bash? I only need to copy alike:
cp -r -v bla.txt ../Long\ Winglets/xx/plugins/b1/
any idea on how to handle $pwd difference on osx? (with a mouseclick on *.command)
Regards Michael
#4
Posted 19 July 2011 - 09:08 PM
Attach your script and I will fix it up.Thanks, but i get an error with that. "line 6 could not cd" or alike.
Yes simplest to only use bash? I only need to copy alike:
cp -r -v bla.txt ../Long\ Winglets/xx/plugins/b1/
any idea on how to handle $pwd difference on osx? (with a mouseclick on *.command)
Regards Michael
#5
Posted 20 July 2011 - 07:39 AM
many thanks. Regards
#!/bin/bash
echo ""
echo "Copying files"
sleep 1
# 2. for each file in the current directory listing
for file in `ls`
do
# 3. Skip it if it's a directory...
if [ -d $file ]
then
echo $file " is a directory."
else
if [ "$file" = "cfile.txt" ]; then
cp $file ../bl\ blbla/ccc/aaaeb/asbg
cp $file ../ee/dsdfadf/asdfasdfa
echo "Copying " $file
sleep 1
fi
if [ "$file" = "file3.ini" ]; then
cp $file ../dfaf\ bdds/S6sfsdfas/sdfsf/fsfsdf
echo "Copying " $file
sleep 1
fi
fi
done
#!/bin/bash
echo ""
echo "Copying files"
sleep 1
# 2. for each file in the current directory listing
for file in `ls`
do
# 3. Skip it if it's a directory...
if [ -d $file ]
then
echo $file " is a directory."
else
if [ "$file" = "cfile.txt" ]; then
cp $file ../bl\ blbla/ccc/aaaeb/asbg
cp $file ../ee/dsdfadf/asdfasdfa
echo "Copying " $file
sleep 1
fi
if [ "$file" = "file3.ini" ]; then
cp $file ../dfaf\ bdds/S6sfsdfas/sdfsf/fsfsdf
echo "Copying " $file
sleep 1
fi
fi
done
#6
Posted 21 July 2011 - 07:44 AM
it seems that I need to cut off with a regex all after the last / from $0 as the path is alike: /somehwere/General Stuff/blalb/blal/
Don't have time now for Mac, maybe next week.
Don't have time now for Mac, maybe next week.
#7
Posted 22 July 2011 - 05:12 PM
Try this
#!/bin/bash
WorkDir=$(cd -P -- $(dirname -- "$0") && pwd -P)
cd "${WorkDir}"
echo ""
echo "Copying files"
sleep 1
# 2. for each file in the current directory listing
for file in `ls`
do
# 3. Skip it if it's a directory...
if [ -d "$file" ] # need quotes if space in folder name.
then
echo "$file is a directory."
else
if [ "$file" == "cfile.txt" ]; then
cp "$file" ../bl\ blbla/ccc/aaaeb/asbg
cp "$file" ../ee/dsdfadf/asdfasdfa
echo "Copying $file"
sleep 1
fi
if [ "$file" == "file3.ini" ]; then
cp "$file" ../dfaf\ bdds/S6sfsdfas/sdfsf/fsfsdf
echo "Copying $file"
sleep 1
fi
fi
done
#!/bin/bash
WorkDir=$(cd -P -- $(dirname -- "$0") && pwd -P)
cd "${WorkDir}"
echo ""
echo "Copying files"
sleep 1
# 2. for each file in the current directory listing
for file in `ls`
do
# 3. Skip it if it's a directory...
if [ -d "$file" ] # need quotes if space in folder name.
then
echo "$file is a directory."
else
if [ "$file" == "cfile.txt" ]; then
cp "$file" ../bl\ blbla/ccc/aaaeb/asbg
cp "$file" ../ee/dsdfadf/asdfasdfa
echo "Copying $file"
sleep 1
fi
if [ "$file" == "file3.ini" ]; then
cp "$file" ../dfaf\ bdds/S6sfsdfas/sdfsf/fsfsdf
echo "Copying $file"
sleep 1
fi
fi
done
#8
Posted 23 July 2011 - 02:38 PM
Thanks but I got an error with your script. Anyway this below works and is more simple:
wherami=$(dirname "${0}") cp "${wherami}/${nameOfTheFileToCopy}" "${wherami}/"../blal/bllb/
wherami=$(dirname "${0}") cp "${wherami}/${nameOfTheFileToCopy}" "${wherami}/"../blal/bllb/
#9
Posted 24 July 2011 - 03:45 AM
Whatever works for you.
Got an error with your script.
Got an error with your script.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users



Sign In
Create Account







