Help with simple bash script for Linuxmint 14 32 bit
Linuxmint 14 Cinnamon 32 bit
I'm a Linux noob trying to learn some bash scripting by example. I tried to implement a bash script which appears in the first comment at this URL: http://showmedo.com/videotutorials/v...omSeriesID=388 but it doesn't work. I get a blank box rather than an MD5 sum. The idea is to select one or more files in Nemo, right-click on it or them, choose "Scripts" and then the script below which is in ~/.gnome2/nemo-scripts. I made it executable for everyone. Here's the original script: Code:
#/bin/sh Code:
#!/bin/sh Code:
#/bin/sh If I open a terminal and type "md5sum some_file_name" I get the desired md5sum. /usr/bin is in my $PATH variable. I have zenity installed and it pops up an empty box with the "Calculate MD5" title. TIA for the help. |
Making the change you did in the first line specifies that you want to use bash with the POSIX restriction enabled. Try the script without that change.
|
I don't use gnome, but according to this, "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" is an automatically set environment variable containing a newline-separated list of the input files.
That's certainly not an especially safe way to handle file inputs. What if a filename itself contains an embedded newline? In any case, the variable is unnecessary, since the script's input arguments also contain the list of input names. You only need to loop directly over them. Code:
#/bin/bash |
[SOLVED] with /bin/bash rather than !/bin/bash
Thank you @PTrenholme. This script now works:
Code:
#/bin/sh Sorry @David the H., but your script just gives me a blank box. |
There's a typo in both the shell invocations above; it should start with '#!', then the path to the desired shell eg bash.
On my system Code:
# this cmd tells you where shell lives |
@chrism01: There was a simple typo in my last post. I corrected it and thank you for your observation. The reason for editing is wrong but the script is now correct. /bin/sh works and /!bin/sh does not work. Haven't tried @David the H.'s script with /bin/sh instead of /bin/bash.
|
I sure did miss it too. It comes from just copying and pasting the original and modifying it. I changed the interpreter name, but failed to catch the missing "!" from it.
And be clear: The shebang always starts with "#!" (hence the name, "sharp+bang"), followed by the path to the interpreter to use. Note that the first character makes it a shell comment too, so that it's ignored if sourced or run with an explicit interpereter call or something. See the ongoing discussion here about the purpose of the shebang. http://www.linuxquestions.org/questi...estion-762082/ In any case my version of the script is pretty much /bin/sh compatible too, except for the advanced test brackets I added. Just change this... Code:
[[ -f $uri ]] && md5sum "$uri" Code:
[ -f "$uri" ] && md5sum "$uri" |
All times are GMT -5. The time now is 12:16 AM. |