Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash alias to Python script -- is it possible?

The particular alias I'm looking to "class up" into a Python script happens to be one that makes use of the cUrl -o (output to file) option. I suppose I could as easily turn it into a BASH function, but someone advised me that I could avoid the quirks and pitfalls of the different versions and "flavors" of BASH by taking my ideas and making them Python scripts.

Coincident with this idea is another notion I had to make a feature of legacy Mac OS (officially known as "OS 9" or "Classic") pertaining to downloads platform-independent: writing the URL to some part of the file visible from one's file navigator {Konqueror, Dolphin, Nautilus, Finder or Explorer}. I know that only a scant few file types support this kind of thing using some other command-line tools (exiv2, wrjpgcom, etc). Which is perfectly fine with me as I only use this alias to download single-page image files such as JPEGs anyways.

I reckon I might as well take full advantage of the power of Python by having the script pass the string which is the source URL of the download (entered by the user and used first by cUrl) to something like exiv2 which could write it to the Comment block, EXIF User Comment block, and (taking as a first and worst example) Windows XP's File Description field. Starting small is sometimes a good way to start.

Hope someone has advice or suggestions.

BZT

like image 434
silversleevesx Avatar asked Dec 04 '22 13:12

silversleevesx


1 Answers

The relevant section from the Bash manual states:

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command.

So, there should be nothing preventing you from doing e.g.

$ alias geturl="python /some/cool/script.py"

Then you could use it like any other shell command:

$ geturl http://example.com/excitingstuff.jpg

And this would simply call your Python program.

like image 91
unwind Avatar answered Dec 21 '22 02:12

unwind