How do I learn python for bash scripting.
Shell Script: Execute a python program from within a shell script - Stack Overflow
Learning python
Can Python (efficiently) replace all bash scripting, or is bash still worth learning/using at times?
In terms of ability, python can do anything bash can do and more.
Some things are quicker to hack up using bash due to existing integrations within the linux ecosystem.
Basic bash scripting is good to know, in case you need to make a bash script that installs a specific python version :)
More on reddit.comHow do I get started with Python?
What jobs use Python?
What is Python used for?
Videos
Factsheet
I’ve learned the basics of a few languages like Java, c and a teeny bit of python.
What I don’t like about software learning is that the end result of a course is that you know what variables and strings are. But you’re left hanging after that and struggle to get better on your own. Most courses I see keep to showing the same basics. I’m looking for something to take to the next level.
I love bash scripting for work mainly automating stuff like createsftpserver.sh and a combo of commands - mainly grep and pawl for finding the text I need.
I’d like to know more about bash like loops and bigger projects.
But I don’t want to invest too much time in bash because python is better in terms of speed and features.
What sort of projects can I do to learn python at a false beginners level that bring you to an advanced stage or project ideas in Python for doing Linux commands.
Just make sure the python executable is in your PATH environment variable then add in your script
python path/to/the/python_script.py
Details:
- In the file job.sh, put this
#!/bin/sh python python_script.py
- Execute this command to make the script runnable for you :
chmod u+x job.sh - Run it :
./job.sh
Method 1 - Create a shell script:
Suppose you have a python file hello.py
Create a file called job.sh that contains
#!/bin/bash
python hello.py
mark it executable using
$ chmod +x job.sh
then run it
$ ./job.sh
Method 2 (BETTER) - Make the python itself run from shell:
Modify your script hello.py and add this as the first line
#!/usr/bin/env python
mark it executable using
$ chmod +x hello.py
then run it
$ ./hello.py