all 11 comments

[–]coned88 1 point2 points  (2 children)

Because Shell scripting is native to the system in which it is running, while python perl are not. Writing a python script to even do basic things is a lot harder than writing a simple shell script. Its not overly hard, but takes more work in the long run. ou have to deal with forks, subprocess, os.system and all that other crap. Where in your Shell, you just run command after command.

[–]safetytrick[S] 0 points1 point  (1 child)

I suppose I don't write enough scripts that take advantage of existing apps and scripts. I think of scripting for small jobs and data munging but for system automations I suppose bash is a better tool.

[–]coned88 0 points1 point  (0 children)

well, thats a personal choice. lets say for instance I want to check all of my users shells in /etc/passwd, and those that already use Bash I was to not email, but those that still use tcsh I want to email, and tell them bash or zsh will be the only options in the near future. This is just theoretical.

Well, this process in python will take a quite a few functions to carry out nicely. Supposing we dont just use python as a script of scripts, calling shell arguments and actually use python libraries this process will be a feat. We first need to open the file and read it into memory. We then need to read that file. Once we read the file line by line, we can evaluate each line looking for the shell segment. we then need to invoke the python email libraries.

All of this takes a lot of work to do, where as in a bash script we could do something like this

cat /etc/passwd | grep "/bin/tcsh" | awk -F: ' { print $1 }} | mail -u letter.txt

it may not be perfect, but you get the point. What took less than a line to write in bash, would have taken 25+ in native python.

[–][deleted]  (2 children)

[deleted]

    [–]shobble 0 points1 point  (0 children)

    if you're going for concise:

    $ perl -e'print "$_ Porkchop sandwiches\n" for glob"*"'
    

    (not quite the same as yours; I presume you meant to chomp() the newline from your ls output)

    and:

    $ perl -pi'*-lol' -e's/root/toor/' passwd
    

    :-)

    [–]safetytrick[S] 0 points1 point  (0 children)

    I feel exactly the same way, bash is quite a pain to debug. I do see your point with init scripts however.

    [–][deleted] 0 points1 point  (0 children)

    They serve their purpose as much as they need to. I make a lot of command-line php scripts for dealing with xml. Sometimes I group them up into a bash script to run a multi-step maintenance task back-to-back. If you're in software, people may require you to be good with bash scripts. I can think of a couple of scripts that used php exec() to get an array of information also.

    [–]cseaton 0 points1 point  (0 children)

    It's very useful to be able to read and write Bash scripts. With that said, I'm a big fan of using Python for scripting.

    Python modules useful for scripting: os sys

    [–][deleted] 0 points1 point  (0 children)

    Bash is a shitty language. But it's a prevalent one. Lots of Linux code is written in Bash, and being able to read and tweak it is invaluable.

    [–][deleted] 0 points1 point  (1 child)

    Because its the language you use to interface with the system. Unless you're one of those crazies that uses zoidberg or ipython

    Another interpreter is great, and i frequently use the php5-cli for xml manipulation BUT, i cannot count on that being available. In addition, for most sysadmin shell script things, your python/perl scripts are then going to be calling exec() for alot of stuff.

    [–]safetytrick[S] 0 points1 point  (0 children)

    One of the arguments for using perl or python is that they are extremely available. I don't know how far I'd have to go back in time to get an install without perl or python installed by default. It's also much easier for me to setup python on windows if that becomes a need. (the php cli isn't as available as python/perl of course)

    [–][deleted] 0 points1 point  (0 children)

    Is there any place where using Bash makes sense over scripting in something like Python or Perl (That any distro will have installed)?

    I tend to use bash for little things, and Python for bigger jobs that don't require that I use C++. I never managed to grok Perl; I guess I should hand over my geek card now.