Help with simple program for terminal

Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
I am new to MAC's for the most part. I want to write q quick small program to change directory and execute a command string. How can I write and compile this file so I can execute it from terminal? Something simple like -

cd ~/desktop/temp
./something -1 blah blah

I know this should be pretty simple. In the PC world I would just create a bat file.

Thanks!
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Simply put those commands in a text document (make sure it's plain text). Open up terminal and type the following to make it executable:
Code:
chmod +x <name of file>
Replace <name of file> with the name of the file. All you have to do now is execute it like you would an application:
Code:
./<script name>
 
OP
N
Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
Ok as simple as it may be, I cannot get it to work. How do I write a text file to convert that will do this -

cd ~/desktop/sample

./sample commands blah blah


I want to do two things, change the directory and then send a command how do a format the text file so I can do the chmod on it? I started by seeing if I could just create the file to change the directory and it doesnt work. I open the text editor on my MAC, changed preferences to make sure it was text and not rtf. I then created a text file called test.txt that had this one line in it -

cd ~/desktop/temp/


I save it, did the chmod +x on it, ran it ./test.txt from the desktop in terminal and nothing happens....

Help?

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Create a file with no extension with the following:
Code:
~/Desktop/sample arguments
Then make it executable:
Code:
chmod +x <script name>
Finally, execute it. You don't need to change directories if you use the full path when executing the application.
 
OP
N
Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
It all seems pretty simple but it is not working. Here is exactly what I am tryin to do. I am trying to create a small executable file I can use to reboot my ATV which I jailbroke. The command and arguments is pretty small but I was just trying to simplify the procress. I need to make a small executible file that does this -

directory with files is ~/desktop/tethered/

file and arguments is -

./tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

I wanted to store the file in my root directory so I could just fire up terminal and type ./<filename> and it would go to the right directory and send the command and arguments. Why is this so hard? It probably isnt!

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You're going to have to help me out here - what isn't working? The steps I outlined should work and without knowing what's not working, I can't help any further.
 
OP
N
Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
Thanks.. here is what I have.. The files are in directory -
/desktop/tethered/

The file to execute with arguments is -
tetheredboot

so I type exactly this and only this into a text file -

~/desktop/tethered/tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

I save it as 'test' with no extension and then do the 'chmod +x test'

When I execute the file from the desktop in terminal I get this error -

Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu'

But to double check it 'should' work. I open the 'tethered' directory in terminal and type 'tetheredboot' with that same argument string as listed and it works.

Why?


EDIT:
If I copy the new script command into the 'tethered' directory it works. So the path in the script works to the point that it points to the file 'tetheredboot' because its trying to execute that command, but it fails unless its executed from the same directory. Why?
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
Try this,
cd ~/desktop/tethered; tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66
 
OP
N
Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.

Also interesting observation... as I mentioned the new script works when executed in terminal from the directory it resides in, but when executed from anywhere else it says - Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu' .. Now if I execute that script by double clicking the script file right in FINDER and not through terminal I get that same error. This tells me that when executing the script in terminal from any other directory its is as if the command is not being sent in terminal mode... does that make sense?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Put the full path to the iBSS.k66ap.RELEASE.dfu file as well in your script:
Code:
~/Desktop/tethered/tetheredboot -i ~/Desktop/tethered/iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.
Well I was just trying to help with my somewhat limited Terminal knowledge, but it seems vansmith knows more about it :D
 
OP
N
Joined
Jan 9, 2011
Messages
7
Reaction score
0
Points
1
That worked once I also added the path to the second argument. For convenience I also changed the directory to 'boot'. This is what worked -

~/boot/tetheredboot -i ~/boot/iBSS.k66ap.RELEASE.dfu -k ~/boot/kernelcache.release.k66

Thank you very much for the help. Do you happen to know of any good sites to learn basic script writing?

Have a good one!
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
None in particular but searching for bash scripting in your search engine of preference will no doubt yield many results.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top