Jump to content

click execute file copy pls debug my file


  • Please log in to reply
8 replies to this topic

#1
derda

derda

    InsanelyMac Protégé

  • Members
  • Pip
  • 47 posts
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

#2
STLVNUB

STLVNUB

    InsanelyMac Legend

  • Coders
  • 1,086 posts
  • Gender:Male
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.

#3
derda

derda

    InsanelyMac Protégé

  • Members
  • Pip
  • 47 posts
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

#4
STLVNUB

STLVNUB

    InsanelyMac Legend

  • Coders
  • 1,086 posts
  • Gender:Male

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

Attach your script and I will fix it up.

#5
derda

derda

    InsanelyMac Protégé

  • Members
  • Pip
  • 47 posts
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

#6
derda

derda

    InsanelyMac Protégé

  • Members
  • Pip
  • 47 posts
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.

#7
STLVNUB

STLVNUB

    InsanelyMac Legend

  • Coders
  • 1,086 posts
  • Gender:Male
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

#8
derda

derda

    InsanelyMac Protégé

  • Members
  • Pip
  • 47 posts
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/

#9
STLVNUB

STLVNUB

    InsanelyMac Legend

  • Coders
  • 1,086 posts
  • Gender:Male
Whatever works for you.
Got an error with your script.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy