Re: [opensuse] different types of shell scripts
On Thu, 22 Sep 2011 21:13:16 +0800, George Olson
Ah, ok, let me see if I comprehend this correctly. So the first example won't create a child process
Nearly right :) The shell always creates a new process, be it for binary programs or an interpreter for a script (a shell, sed, awk, perl etc.). As others wrote, '.' means "let the current shell run the given script".
But the second example will create a child process because by using the /myscript.sh, the current directory is automatically included in PATH (indicated by the /, which puts some kind of root action on the call?),
No. A normal user has '.' in his/her path by default, as you can check by doing 'echo $PATH'. The user root doesn't have '.' in PATH for the reasons I wrote. cu Philipp -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, Sep 23, 2011 at 5:02 PM, Philipp Thomas
On Thu, 22 Sep 2011 21:13:16 +0800, George Olson
wrote: Ah, ok, let me see if I comprehend this correctly. So the first example won't create a child process
Nearly right :) The shell always creates a new process, be it for binary programs or an interpreter for a script (a shell, sed, awk, perl etc.). As others wrote, '.' means "let the current shell run the given script".
To be pedantic the above is either a little strong or unclear (I'm not sure which). Suppose I have a "file" (not a script) that has content: ### TEST_DEV=/dev/sda3 echo $TEST_DEV ### If I source that (. filename) it will not create a new process. The shell itself is able to process those commands. (It has a built-in echo command.) If I execute the above (./filename or just plain filename) then a new shell child process is invoked to run the commands. If I modify the file to say: ### TEST_DEV=/dev/sda3 /bin/echo $TEST_DEV echo $TEST_DEV ### Then when I source the file, a child process (/bin/echo) is launched, but only for that one command, the first and last are still processed by the original shell. And if I execute the file I get both a child shell process and a grandchild /bin/echo process. Greg -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Fri, 23 Sep 2011, Greg Freemyer wrote:
Suppose I have a "file" (not a script) that has content:
### TEST_DEV=/dev/sda3 echo $TEST_DEV ###
If I source that (. filename) it will not create a new process. The shell itself is able to process those commands. (It has a built-in echo command.)
Correct. xterm1> cat /tmp/t.sh TEST_DEV=/dev/sda3 echo $TEST_DEV /bin/echo $TEST_DEV xterm1> echo $$ 3236 xterm2> LANG=C strace -f -e process -p 3236 xterm1> . /tmp/t.sh /dev/sda3 /dev/sda3 [meanwhile on xterm2, pruned to the relevant syscalls] clone(Process 24593 attached [pid 24593] execve("/bin/echo", ["/bin/echo", "/dev/sda3"], [/* 125 vars */]) = 0 Process 3236 resumed Process 24593 detached --- SIGCHLD (Child exited) @ 0 (0) --- xterm1> /tmp/t.sh /dev/sda3 /dev/sda3 [meanwhile on xterm2, pruned to the relevant syscalls] clone(Process 24635 attached [pid 24635] execve("/tmp/t.sh", ["/tmp/t.sh"], [/* 125 vars */]) = -1 ENOEXEC (Exec format error) [pid 24635] execve("/bin/sh", ["/bin/sh", "/tmp/t.sh"], [/* 125 vars */]) = 0 [pid 24635] clone(Process 24636 attached child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f55576939d0) = 24636 [pid 24636] execve("/bin/echo", ["/bin/echo", "/dev/sda3"], [/* 122 vars */]) = 0 Process 24635 resumed Process 24636 detached [pid 24635] --- SIGCHLD (Child exited) @ 0 (0) --- Process 3236 resumed Process 24635 detached --- SIGCHLD (Child exited) @ 0 (0) ---
If I execute the above (./filename or just plain filename) then a new shell child process is invoked to run the commands.
If I modify the file to say:
### TEST_DEV=/dev/sda3 /bin/echo $TEST_DEV echo $TEST_DEV ###
Then when I source the file, a child process (/bin/echo) is launched, but only for that one command, the first and last are still processed by the original shell.
And if I execute the file I get both a child shell process and a grandchild /bin/echo process.
Correct. See above. Don't speculate, use the tools ;) -dnh -- I find all proselytisation to be misguided at least. The way I see it, it's not the Enlightened or the Chosen trying to save me or anyone, but just some meme trying to survive in the great war for brain real estate. -- Maarten Wiltink -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday, September 23, 2011 16:02:28 Philipp Thomas wrote:
No. A normal user has '.' in his/her path by default, as you can check by doing 'echo $PATH'. The user root doesn't have '.' in PATH for the reasons I wrote.
i'll take issue with that last -- i was always told it is dangerous and scary to put '.' in path, and have never seen a distribution (in my limited experience) that puts it there by default i have several directories where i work on specific, isolated projects -- my solution is to have two functions in my ~/.bashrc that add or remove $(pwd) to or from PATH -- i quote the relevant section below: ———————————————————————————————————————— # dangerous path extension of %PWD function dp () { if [[ $PATH = $PWD:* ]] then echo "PATH already has $PWD" else export PATH=${PWD}:$PATH export PS1='\w: ' fi } # remove dangerous path extension -- whew! function rdp () { export PATH=${PATH#$PWD:} export PS1='\w> ' } ———————————————————————————————————————— they also tweak the PS1 so i can tell by looking if i've done a 'dp' already, and to remind me it's done sc N�����r��y隊Z)z{.�ﮞ˛���m�)z{.��+�Z+i�b�*'jW(�f�vǦj)h���Ǿ��i�������
Hello, On Fri, 23 Sep 2011, sc wrote:
On Friday, September 23, 2011 16:02:28 Philipp Thomas wrote:
No. A normal user has '.' in his/her path by default, as you can check by doing 'echo $PATH'. The user root doesn't have '.' in PATH for the reasons I wrote.
i'll take issue with that last -- i was always told it is dangerous and scary to put '.' in path, and have never seen a distribution (in my limited experience) that puts it there by default
==== /etc/sysconfig/suseconfig [SUSE 11.4/64bit] ==== # # Do you want to have "." in root path? This is not recommended, but # many people do prefer it (yes/no). The setting affects all system # users (with uid < 100) # CWD_IN_ROOT_PATH="no" ## Type: yesno ## Default: yes # # Do you want to have "." in the path for normal users? # Defaults to "yes" since this has been the case for years. # CWD_IN_USER_PATH="no" ==== I'm not 100% sure if that's the 11.4 default, as this is an upgrade from 11.1 via 11.2 and that file might have been kept. HTH, -dnh -- "No one goes mad quicker than a totally sane person." -- Terry Pratchett, The Light Fantastic, p. 193 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sat, Sep 24, 2011 at 12:36:20AM +0200, David Haller wrote: [ 8< ]
I'm not 100% sure if that's the 11.4 default, as this is an upgrade from 11.1 via 11.2 and that file might have been kept.
grep CWD_IN_ /var/adm/fillup-templates/sysconfig.suseconfig CWD_IN_ROOT_PATH="no" CWD_IN_USER_PATH="yes" For openSUSE 11.4 and Factory. Lars -- Lars Müller [ˈlaː(r)z ˈmʏlɐ] Samba Team SUSE Linux, Maxfeldstraße 5, 90409 Nürnberg, Germany
Hello, On Sat, 24 Sep 2011, Lars Müller wrote:
On Sat, Sep 24, 2011 at 12:36:20AM +0200, David Haller wrote: [ 8< ]
I'm not 100% sure if that's the 11.4 default, as this is an upgrade from 11.1 via 11.2 and that file might have been kept.
grep CWD_IN_ /var/adm/fillup-templates/sysconfig.suseconfig CWD_IN_ROOT_PATH="no" CWD_IN_USER_PATH="yes"
For openSUSE 11.4 and Factory.
Thank you! So the default hasn't changed yet. I think it should. NOW! Let's have a default of (implicitly) CWD_IN_USER_PATH="no" with 12.2 at latest. Oh, what I don't remember[1] is at what position "." got added to PATH if that variable was set to "yes". If last, just get rid of it, if first, change it to "last" with 12.1. That stupidity has stuck around far far too long already. Those who want to shoot themselves can still use it by setting CWD_IN_USER_PATH to "yes" ;) Oh, and BTW: I plead for removing the variable for root altogether. root should _never ever_ have "." in his PATH. -dnh, using S.u.S.E since 5.3 and _never_ having "." in _any_ PATH. [1] if I ever tried it ;) -- Es fehlt die Glaskugel, die voraussagen kann, welche der anderen Glaskugeln heute am genauesten glaskugelt. -- Christoph Päper in drtm -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday, 2011-09-24 at 15:58 +0200, David Haller wrote:
So the default hasn't changed yet. I think it should. NOW! Let's have a default of (implicitly)
CWD_IN_USER_PATH="no"
Bugzilla? - -- Cheers, Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAk598ZYACgkQtTMYHG2NR9WcXACcDv2ont3uZjPxGqk5dEaPTHtG vrEAn20xt9ZPyhSi/8wUwKvIZcEA34wQ =hg02 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Moining, On Sat, Sep 24, 2011 at 03:58:46PM +0200, David Haller wrote:
On Sat, 24 Sep 2011, Lars Müller wrote:
On Sat, Sep 24, 2011 at 12:36:20AM +0200, David Haller wrote: [ 8< ]
I'm not 100% sure if that's the 11.4 default, as this is an upgrade from 11.1 via 11.2 and that file might have been kept.
grep CWD_IN_ /var/adm/fillup-templates/sysconfig.suseconfig CWD_IN_ROOT_PATH="no" CWD_IN_USER_PATH="yes"
For openSUSE 11.4 and Factory.
Thank you!
So the default hasn't changed yet. I think it should. NOW! Let's have a default of (implicitly)
CWD_IN_USER_PATH="no"
with 12.2 at latest. Oh, what I don't remember[1] is at what position "." got added to PATH if that variable was set to "yes".
Are you getting more and more lazy? Must be the age. ;) From /etc/profile.d/profile.sh CWD_IN_USER_PATH=*) test "$val" = "yes" || continue test $UID -ge 100 && PATH=$PATH:.
If last, just get rid of it, if first, change it to "last" with 12.1. That stupidity has stuck around far far too long already. Those who want to shoot themselves can still use it by setting CWD_IN_USER_PATH to "yes" ;)
I suggest to keep it simple stupid and to change the default of CWD_IN_USER_PATH to no
Oh, and BTW: I plead for removing the variable for root altogether. root should _never ever_ have "." in his PATH.
@Rudi: As you added CWD_IN_USER_PATH only ten years back you might still remember why these two settings are needed. ;) Lars -- Lars Müller [ˈlaː(r)z ˈmʏlɐ] Samba Team SUSE Linux, Maxfeldstraße 5, 90409 Nürnberg, Germany
Hello, On Sat, 24 Sep 2011, Lars Müller wrote:
On Sat, Sep 24, 2011 at 03:58:46PM +0200, David Haller wrote:
On Sat, 24 Sep 2011, Lars Müller wrote:
On Sat, Sep 24, 2011 at 12:36:20AM +0200, David Haller wrote: [ 8< ]
I'm not 100% sure if that's the 11.4 default, as this is an upgrade from 11.1 via 11.2 and that file might have been kept.
grep CWD_IN_ /var/adm/fillup-templates/sysconfig.suseconfig CWD_IN_ROOT_PATH="no" CWD_IN_USER_PATH="yes"
For openSUSE 11.4 and Factory.
Thank you!
So the default hasn't changed yet. I think it should. NOW! Let's have a default of (implicitly)
CWD_IN_USER_PATH="no"
with 12.2 at latest. Oh, what I don't remember[1] is at what position "." got added to PATH if that variable was set to "yes".
Are you getting more and more lazy? Must be the age. ;)
Quite likely. I am and always were and are lazy. And/or the fact that I'm 30+hrs awake ;)
From /etc/profile.d/profile.sh
CWD_IN_USER_PATH=*) test "$val" = "yes" || continue test $UID -ge 100 && PATH=$PATH:.
Ah :)
If last, just get rid of it, if first, change it to "last" with 12.1. That stupidity has stuck around far far too long already. Those who want to shoot themselves can still use it by setting CWD_IN_USER_PATH to "yes" ;)
I suggest to keep it simple stupid and to change the default of CWD_IN_USER_PATH to no
Jep. Seconded. What I was saying.
Oh, and BTW: I plead for removing the variable for root altogether. root should _never ever_ have "." in his PATH.
@Rudi: As you added CWD_IN_USER_PATH only ten years back you might still remember why these two settings are needed. ;)
Hm. I'm rather sure that there was something like that (somewhere in /etc/rc.config?) in SuSE 6.2 ('99) and before. Ah, yes, in the backup of my ex-6.2 box (the infamous one ;) I find: ==== etc/rc.config ==== # Do you want to have "." in root path? This is not recommended, but # many people do prefer it (yes/no). # CWD_IN_ROOT_PATH="no" ==== and commented out by me: ==== etc/profile ==== ## Moved to profile.local #### # PATH=/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin[:...?] [..] # test "$UID" = 0 || PATH="$PATH:." # export PATH #### ==== Both files from my 6.2 install (around Aug. 16, 1999). So, CWD_IN_USER_PATH was probably introduced for "backward compatibility". -dnh -- "Powered-up hardware and sweat do not mix." -- Simon Cozens -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/23/2011 05:02 PM, Philipp Thomas pecked at the keyboard and wrote:
On Thu, 22 Sep 2011 21:13:16 +0800, George Olson
wrote: Ah, ok, let me see if I comprehend this correctly. So the first example won't create a child process
Nearly right :) The shell always creates a new process, be it for binary programs or an interpreter for a script (a shell, sed, awk, perl etc.). As others wrote, '.' means "let the current shell run the given script".
But the second example will create a child process because by using the /myscript.sh, the current directory is automatically included in PATH (indicated by the /, which puts some kind of root action on the call?),
No. A normal user has '.' in his/her path by default, as you can check by doing 'echo $PATH'. The user root doesn't have '.' in PATH for the reasons I wrote.
cu Philipp
Normal users on my unmodified (never changed the default path) systems do not have a "." in their path. -- Ken Schneider SuSe since Version 5.2, June 1998 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday, 2011-09-23 at 23:02 +0200, Philipp Thomas wrote:
No. A normal user has '.' in his/her path by default,
I don't :-) - -- Cheers, Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAk59EUgACgkQtTMYHG2NR9Xz9QCglzifWA9inBDSZP1hE8VSq6HZ c5oAnj3N0MaHRpAS0gBMxiqpvmwXrSRt =45Xn -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Carlos E. R.
-
David Haller
-
Greg Freemyer
-
Ken Schneider - openSUSE
-
Lars Müller
-
Philipp Thomas
-
sc