Re: PATH and $0
On Tue, Jul 11, 2006 at 08:19:34PM -0400, Dave Rutherford wrote: > On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: > >I want its full pathname using 'dirname', but it will give me > >unexpected result on some Linux or Bash versions. > > Well, 'dirname' certainly won't do what you want, but I'm sorry, > I can't think of a way to get what you need. (It would be relatively > easy in 'c'.) Even /proc/self/* doesn't contain the script's full > pathname. Perhaps somebody else knows a better way. [...] $0 will always contain the file path, unless the script was started as: bash script.sh And there's no script.sh in the current directory (in which case sh/bash will have looked up script.sh in $PATH). So: #! /bin/sh - dir=$( cmd=$0 [ -e "$cmd" ] || cmd=$(command -v -- "$cmd") || exit dir=$(dirname -- "$cmd") cd -P -- "$dir" && pwd -P ) || exit # untested should give you the absolute path of the directory portion of the script path (unless that directory ends in newline characters). -- Stephane ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
automatic code generation
I'm trying to a write a script to automatically generate some .cpp & .h files. I have the templates in external files which look something like this: void ${NAME}Panel::showEvent(QShowEvent *e) { ...code } I want to be able to run my script, have it read the contents of the files while replacing ${NAME} with a variable that is defined elsewhere in my script. My issue is that I can't get NAME to bind to anything in the .cpp file I generate. By this I mean that if ${NAME} evaluates to Foo in the script, when I output the file I still get void ${NAME}Panel::showEvent(QShowEvent *e) { ...code } when what I want is void FooPanel::showEvent(QShowEvent *e) { ...code } Any suggestions? -- View this message in context: http://www.nabble.com/automatic-code-generation-tf1932672.html#a5294509 Sent from the Gnu - Bash forum at Nabble.com. ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: automatic code generation
box <[EMAIL PROTECTED]> wrote: > void ${NAME}Panel::showEvent(QShowEvent *e) { > ...code > } > > I want to be able to run my script, have it read the contents of the files > while replacing ${NAME} with a variable that is defined elsewhere in my > script. NAME=... eval "cat < output-file paul ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash
Re: PATH and $0
Hi, On 7/12/06, Stephane Chazelas <[EMAIL PROTECTED]> wrote: On Tue, Jul 11, 2006 at 08:19:34PM -0400, Dave Rutherford wrote: > On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: > >I want its full pathname using 'dirname', but it will give me > >unexpected result on some Linux or Bash versions. > > Well, 'dirname' certainly won't do what you want, but I'm sorry, > I can't think of a way to get what you need. (It would be relatively > easy in 'c'.) Even /proc/self/* doesn't contain the script's full > pathname. Perhaps somebody else knows a better way. [...] $0 will always contain the file path, unless the script was started as: bash script.sh And there's no script.sh in the current directory (in which case sh/bash will have looked up script.sh in $PATH). So: #! /bin/sh - dir=$( cmd=$0 [ -e "$cmd" ] || cmd=$(command -v -- "$cmd") || exit dir=$(dirname -- "$cmd") cd -P -- "$dir" && pwd -P ) || exit # untested should give you the absolute path of the directory portion of the script path (unless that directory ends in newline characters). -- Stephane Yes, $0 always has full path, even if I am using alias. It is a problem in my side anyway. Thanks, Qian ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash