3 ms·
Personally, I just don't bother trying to show the user their particular invocation: #!/bin/bash echo "Usage: $(basename $0) [OPTIONS]"
by ilikepi 8y ago
Personally, I just don't bother trying to show the user their particular invocation:
#!/bin/bash
echo "Usage: $(basename $0) [OPTIONS]"
- Crestwave 8y agoMinor nitpick, but wouldn't ${0##*/} work as well?
- ilikepi 8y agoYep! Not a nitpick at all. There's more than one way to do lots of things. I prefer my version because it's easier for me to remember and read. I do use pattern substitution for other things, but I usually have to go to an interactive shell and create a test variable in order to remind myself whether I want # or %. I understand favoring built-in features over subshell calls for heavily used code, but I don't think this is especially critical for outputting usage info.
- LukeShu 8y agoYes, that's what we've been stuck doing, because the full path included in $0 is useless if the program was run via $PATH.