Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

carterx

macrumors member
Original poster
Dec 4, 2006
57
13
For the past few years I get by with AppleScripts and Shell/Bash scripts mostly with researching and trial by doing, testing, breaking etc. but I would actually like to sit down and really learn the core of a scripting language rather than just relying on what I find online.

I have AppleScripts but these cannot be used with Apple's Profile Manager and Login Scripts/Hooks which I'm starting to use a lot now.

I guess my question is, should I be learning Shell/Bash scripts or maybe Apple's Swift will in time be able to handle similar tasks that Shell handles.

What would you recommend for and IT Administrator that handles countless deployments of Mac labs, use of Profile Manager, Munki etc. What would be more beneficial to sink my time into. I'm willing to do the training but want to try and figure out which would be best to start with.

Thank you for your in put and suggestions.
 
How about Makefile scripting? Just kidding. (But Makefiles can do crazy stuff)

Bash isn't a bad choice for Sys-Admin duties. You should learn it anyway. But the language and the constructs it allows are somewhat limited. It would be possible to 'outgrow' the language pretty quickly.

Python is probably a better choice. It's a much more flexible laguage and is useful for Sys-Admin duties. Personally, I love using perl. But I can't say I recommend it at this point. Not as much momentum behind it as python.

Swift is really a different thing. It's designed for native application development and inter-operability with Objective-C which doesn't sound like what you're looking for.

Remember that you should always be learning new things. Languages are tools. Different tools are better for different jobs. If you always try to solve every problem with a screwdriver, you won't be as effective as you could be.
 
I'd agree with the above. A lot of system admin type stuff can be done with bash scripts. I'm not sure how much better Python is since I've always found bash more than adequate for my needs. Bash can be a bit quirky and clunky, but it gets the job done.
 
  • Like
Reactions: carterx
I guess my question is, should I be learning Shell/Bash scripts or maybe Apple's Swift will in time be able to handle similar tasks that Shell handles.

It depends what you're doing - I'd say Applescript/Automator for automating tasks using GUI-based applications, Bash for automating tasks using command-line utilities (plus a bit of research into what you can do with CLI tools) and your choice of Python, Perl, Ruby or even PHP in cases where more substantial/complex logic is required. Important point is - these are all pre-installed on every Mac (although maybe not the newest versions). AFAIK the Swift compiler is only there if you install XCode (so you'd have to compile everything to binary) and the other contender might be Node.JS/Javascript which, again, has to be installed on the target machine.

Out of Python/Perl/PHP/Ruby it depends what else you are doing: e.g. PHP makes a perfectly serviceable scripting language (fugly - but a huge range of useful and mature* libraries) for admin tasks but the main reason you'd choose it is if you knew it well from web development.

(* a few years back, when I wanted to munge iTunes playlists using XML files PHP offered a single, complete XML/XPath implementation using the familiar Apache libraries but all I could find for Python was half-a-dozen half-finished libraries and lots of online arguments about what a 'pythonesqe' XML API would look like).
 
  • Like
Reactions: carterx
Bash is never the correct choice. You can debate between Python, Perl, Ruby, and PHP, but Bash is never the right choice.

Personally, I say go with Python. There's a free book online for learning it called Learn Python the Hard Way, which I recommend for beginners. The same author makes a similarly titled book for Ruby - I have not read it, but I assume it's just as good.
 
  • Like
Reactions: carterx
Look into Bash, it's not that difficult (just a little chaotic, sometimes) and it's probably the most useful thing for every OSX/BSD/Linux admin. You can learn the basics in days and when you know Bash, you can communicate with (and write scripts for) virtually every (non-Windows) machine out there. Bash is THE standard.

Sure, there are great languages like Ruby or Python or even Perl to help you with those more complicated jobs, but both Ruby and Python are pretty easy to pick up when you actually need them - and without knowing Bash ( knowing how to use the terminal) you can't even run Ruby/Python code properly.

And definitely forget about Swift, Swift is a high level compiled language designed to replace Objective C and do the heavy lifting, not a simple scripting language.
 
  • Like
Reactions: carterx
If you're set on learning a shell scripting language, I recommend the plain old Bourne shell rather than bash. Bash is found on OS X and most of the Linux world, but you can't always count on it being there on most other operating systems. The BSDs and various commercial Unix systems won't have it. Everything includes sh.

Python or Perl will obviously allow you to do more than any shell script though.
 
  • Like
Reactions: carterx
What I've found in my own experience is that I use shell scripting (tcsh in my case) for quick knock-off work or simple actions, and python when things start to get more complicated or if it's something that I expect to be around and in use for a while. In both cases, I'm typically controlling compiled codes (mine or third party) that can be in whatever language you want.
 
Bash is never the correct choice. You can debate between Python, Perl, Ruby, and PHP, but Bash is never the right choice.

Sure, bash has many flaws and we could spend a long time detailing the superiority of Python or PHP or whatever. However, I think it's a bit extreme to say that bash "is never the right choice". The Terminal's default shell is bash so it seems sensible to me to at least get the hang of the basics in bash before exploring other options - many of which, as you rightly say, are superior.
 
Bash is never the correct choice. You can debate between Python, Perl, Ruby, and PHP, but Bash is never the right choice.

Personally, I say go with Python. There's a free book online for learning it called Learn Python the Hard Way, which I recommend for beginners. The same author makes a similarly titled book for Ruby - I have not read it, but I assume it's just as good.
"A hammer is never the correct choice. You can debate between torque wrenches, allen wrenches, axes, and pneumatic drills, but a hammer is never the right choice."

I'd say it depends a bit on what you want to achieve. :)
 
  • Like
Reactions: superscape
Python is the highest ranked scripting language on the TIOBE popularity list. There's a ton of educational and tutorial material on Python. It's more popular than Ruby and more readable than Perl. It's also included with OS X as well as what Google uses for scripting stuff. There's even a few Python interpreters in the App store that will run iOS devices.

But one can script on OS X in Swift: http://practicalswift.com/2014/06/07/swift-scripts-how-to-write-small-command-line-scripts-in-swift/
 
  • Like
Reactions: ArtOfWarfare
  • Like
Reactions: Mikael H
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.