Conversation started Mar 14, 2014 at 2:18.
Mar 14, 2014 02:18
What was I doing to poor sed? I highlighted in bold because it's super-important people understand that . will run everything you point it at. Saying "source doesn't run the script" was scary.
slm
slm
@mikeserv you're delivery needs work
and you back it up with 0 facts
@mikeserv it doesn't, it sources it. That results in statements being executed but its relationship to the parent shell is completely different
slm
slm
show that this is the case, otherwise you're just rebutting it to me and making me have to do ALL the work
It is executed - run - in the same way any script is run - either in the current shell process or a child.
Ok, slm, that's a very good point. I can do that.
@mikeserv try this:
Mar 14, 2014 02:20
If I'm wrong I
echo xclock > foo; source foo
slm
slm
sourcing takes each of the commands and runs them one by one in the context of the shell as children
'll delete it.
@mikeserv basically, we kinda expect people to do their homework before posting comments.
And foget that xclock thing, that works, hmmm.
slm
slm
@mikeserv - yes but instead of using DOES and bold you could be a little bit more constructive on the site
Mar 14, 2014 02:21
Oh, yeah, I'm not totally sure of, which is why I said "as far as I know - I could be wrong" - thew important part is that it's run. leading people to believe otherwise is scary.
slm
slm
yes but your choice of words is misleading to passer bys
DOES and bold were the important things.
slm
slm
You're being a drumhead w/o any additional facts and making me have to prove you wrong
No, it was very clear - the script is run!
slm
slm
instead prove that I'm wrong with some actual facts
Mar 14, 2014 02:23
@mikeserv be humble when you are not sure, the use of bold and CAPS are irrelevant whenever you aren't 1000% sure you should be using them
Ok, that is a good point. I think terdon just did thouh.
I am sure that the script is run - I am not sure that the difference is only that dropped safety mechanism.
Here is a fact: (an example of how to back something up)
>. (a period)
. filename [arguments]
Read and execute commands from the filename argument in the current shell context.
@mikeserv I did?
you got to love zsh:
Mar 14, 2014 02:25
source: bash info manual
> . file [ arg ... ]
Read commands from file and execute them in the
environment.

If file does not contain a slash, or if PATH
shell looks in the components of $path to find
containing file. Files in the current directory
unless `.' appears somewhere in $path. If a
`file.zwc' is found, is newer than file, and is
form (created with the zcompile builtin) of file,
are read from that file instead of file.
I'm doing it now.
slm
slm
The diff. b/w a source and a execution is that the commands get run directly as child processes within the context of the current shell, when you run them in a script, they get executed as children under an entirely different shell
> source file [ arg ... ]
Same as `.', except that the current directo-
searched and is always searched first, before
$path.
They are run.
Mar 14, 2014 02:26
they are the same, just that sources look first in the current directory and then in the $PATH
execute is the terminology used
He used "source doesn't run a script"
It does.
This builtin is equivalent to source.
(referrering to dot)
slm
slm
source isn't running a script, it's reading the contents of that file and running the commands one at a time
@mikeserv not quite:
> The command source does not run another script. Merely it pulls the contents of this other script into this script, and then runs its content as if it was originally part of the calling script.
Mar 14, 2014 02:28
and as @slm points out, the context of the execution is quite important.
He said it does not run another script.
slm
slm
using source or . is equivalent to an include
Very important!
@slm oh dear, bringing up C, ain't ya?
;)
@mikeserv since the conversation is getting chaotic, use the arrow to the left hand side of posts to answer them so we know which statement you are answering
slm
slm
Mar 14, 2014 02:29
Can we have a moratorium on empahsis' 8-)
That was why I didnt want a casual reader to mistake "source doen't run a script" for "nothing will happen."
@mikeserv read what he wrote, he said it doesn't run another script.
He's technically right - except that his wording was dangerous, in my opinion.
slm
slm
@mikeserv - the attitude you're taking is off, IMO. I wrote the A and now you're putting a big, incorrect warning at the bottom, forcing me to have to do your homework
He's technically right means he is actually right. Right?
slm
slm
Mar 14, 2014 02:31
@mikeserv - so the next time this happens do some follow up with the author first before jumping the gun
Take it on, then. No I am doing the homework now. Or I would if this window would be stop beeping at me.
slm
slm
ha
ok, now everyone stop
slm
slm
the beeping made me laugh
I didn't jump any guns - another script is run.
Mar 14, 2014 02:32
@slm @slm @slm @slm@slm@slm so there :)
In the current shell environment.
slm
slm
I have it muted
damn
@slm sed, it's okay now. show us on the doll where the shell touched you.
@mikeserv please, if you are not going to continue a constructive conversation, please just move on
Mar 14, 2014 02:33
In his defense, he's not being very aggressive here. Just slightly stubborn.
This is not constructive? You do not believe another script will be run if I source it from a different one?
slm
slm
I'm trying to keep this light
I just don't like things to scalate
slm
slm
me neither
perhaps it's the word run that's the hang up?
@mikeserv is just not! read the man page, and documentation, how can you interpret them as "running another script"?
Mar 14, 2014 02:34
@slm you may have never said it but we assume it. you're good
Thanks, terdon. Me either, I didn't mean any harm - I don't bear anyone ill will - I like argument - it's how you get correct.
. file <- my shell executes the contents of a script. ./file <- my shell spawns a subshell to execute the contents of a script.
slm
slm
yeah let's not argue, let's discuss in a light and friendly manner
we don't need any hostile arugments here, let's break it down so that ppl understand what's going on, w/ examples works best, saying things work a certain way with being to demonstrate them is discouraged
example:
casey@convect ~ % cat setvar.sh
#!/bin/bash

TESTVAR=testtest

casey@convect ~ % ./setvar.sh ; echo $TESTVAR

casey@convect ~ % . ./setvar.sh ; echo $TESTVAR
testtest
slm
slm
@casey - yes that's how I would put that too
Mar 14, 2014 02:36
as I'm not exporting TESTVAR, it is only visible in the shell that sets it
@casey why the .sh termination if it's a bash script ;)
@Braiam why not? :)
(just for the record, I did not make that up myself. chat.stackexchange.com/transcript/127?m=14131611#14131611)
@strugee O_O
@Braiam a better question is why did I write a bash script to run in zsh :)
slm
slm
Mar 14, 2014 02:38
This is kinda of a datapoint:
$ strace -s 2000 -o m.log . somefile.txt
strace: exec: Permission denied
I tried to run . somefile.txt
the contents of that file?
@Braiam yeah
. <<-\SCRIPT /dev/stdin
script=script1 ; echo $script is run
. 3<<\SCRIPT /dev/fd/3
script=script2 ; echo $script is run
SCRIPT
@slm is builtin, it can't spawn a new process
slm
slm
$ more somefile.txt
echo "hi mike"
echo "sam sourced this"
Oh - you need a <tab> in front of the final SCRIPT
Mar 14, 2014 02:39
@casey err... yeah...
@mikeserv could you drop the caps' please (again)
slm
slm
@Braiam that's kinda my point
we are not blind
All commands are run - why? Well, that's just how I denote heredocuments.
slm
slm
pls stop w/ the bold
how many times do i have to ask
@mikeserv all shell commands are run, see slm's example where echocannot be run
slm
slm
Mar 14, 2014 02:41
I DONT NEED THEM I CAN READ!
DO YOU LIKE IT BACK?
source cannot necessarily execute an arbitrary script
I don't care. But that was just the code.
It does.
That's its job.
@mikeserv I'm kinda feeling your only point to arge is a unclear semantic, no an inaccurate answer
Exactly!
the answer is correct, just upvote it!
Mar 14, 2014 02:42
I did.
we are not ELL to discuss semantics
Well, another script is run, and its a little scary to suggest otherwise.
The rest was awesome.
run == execute for most of us, depending the context it could also mean parsed, etc.
slm
slm
I'm still lost
just that something is actioned and some result is expected
if it doesn't it just don't run
Mar 14, 2014 02:44
It is executed - every command therein - even exec. It's not exec(3)'d - it diesn't replace the process.
@mikeserv is English your native language? No offense if it is, but @slm's wording was quite precise.
It does run. Of course. My keyboard sucks. It's this little portable Logitech dealie with a builtin mousepad - you're on my tv.
slm
slm
huh?
cool, I've always wanted to be on TV. Has it been 15 minutes yet?
@mikeserv are you the NSA that we are on your TV?
Mar 14, 2014 02:46
I don't think so - everyone here keeps talking about exec(3) but is there a literal run(3)? The wording was ambiguous in that sense.
Yeah.
NSA.
@slm HDMI?
@mikeserv that you should ask to the ones that make the wonderful thing called UNIX ;)
slm
slm
I wish I was on the playboy channel
4
@slm O_O
Seriously though, the wording was that it doesn't run another script, as in starting a new subshell but instead brings the commands into the current one. That's something we all agree on right?
@slm No offense but I'm glad you're not :P
Mar 14, 2014 02:48
Well, I preferr pedantic arguments to porn I guess. Says quite a lot about me I suppose.
It does run another script.
We're all geeks here, pedants by trade and nature
if we're going to do this argument anymore I need some popcorn
slm
slm
I prefer not arguing at all and working it out in a calm and carefree environment with fellow humans that I would consider my friends
gives some to @strugee
aw thanks
Mar 14, 2014 02:49
<--- always have popcorn
@mikeserv it depends on what you mean by running. Normally, running a script means starting a subshell for that script. That is not the case for source
slm
slm
I was thinking of a beer to go with my playboy
@terdon boom chick booom chick chick.....not sure how to type the music...
Well, there's a mental image I could have done without :)
slm
slm
me w/ a beer?
I like arguing with my friends. It's how I learn. Sorry to bum everyone out. I didn't mean anything was bad - I don't read bad posts far enough in to make it to the comment block.
slm
slm
Mar 14, 2014 02:51
there a compliment, I'll take it
I didn't say run - slm did.
I used the same terminology.
That's all - I referenced your language, dude.
slm
slm
I didn't have any issues with my terminology, dude
@mikeserv we all like (friendly) arguments, so, how do you defend this statement?
> POSIX's . DOES run the other script in the current shell environment.
Well, I think first it needs an accusation.
slm
slm
That was the one that should've included a link to a standard somewhere
What is your line of work? I'm thinking lawyer?
Mar 14, 2014 02:54
NAME

dot - execute commands in the current environment
SYNOPSIS

. file

DESCRIPTION

The shell shall execute commands from the file in the current environment.

If file does not contain a <slash>, the shell shall use the search path specified by PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the dot utility need not be executable. If no readable file is found, a non-interactive shell shall abort; an interactive shell shall write a diagnostic message to standard error, but this condition shall not be considered a syntax error.
slm
slm
Why is everything so adversarial?
Adversarial? I was just asked to defend myself.
In any case, there's the homework.
slm
slm
I don't see anything here that's disagreeing w/ what I characterized?
@mikeserv indeed it is. And I was contesting your statement about not having used run. Which you then explained as using @slm's terminology.
Didn't I?
slm
slm
Mar 14, 2014 02:56
Can we pls use the replies?
I wish my wife wasn't asleep, I'd make some popcorn
slm
slm
the little arrow to the left?
@slm like this
@slm You said it's not run. It's run - apparently executed, even. And yeah, sorry.
@casey How can she sleep when someone is wrong on the internet!
2
slm
slm
Mar 14, 2014 02:57
The file is not run, the lines inside it are
https://lh3.ggpht.com/-Rc8k_D3yYoE/Tw4IyOKMysI/AAAAAAAAAls/awgasVzJMfA/s320/Stephen-Colbert-Popcorn.gif
(filler text)
@terdon I'll never understand it.
@terdon @terdon I wonder that myself. this is serious business.
slm
slm
nice
OK guys, how about this: @slm will edit his answer to remove the ambiguity and @mikeserv will delete his comment. Deal?
Mar 14, 2014 02:57
@slm What...?
slm
slm
"The shell shall execute commands from the file in the current environment. "
@terdon can we call the agreement the U&L Treaty of 14 March 2014?
slm
slm
what am I missing?
@mikeserv He means that the commands within the file are executed but the file is not walked as a script.
@mikeserv is a reverence to some comic xkcd.com/386
Mar 14, 2014 02:58
@terdon Yeah - that was my suggestion when iI came in here. I'd be more than happy to - it was a good post!
slm
slm
as in chmod +x somefile
./somefile
@casey hang on, see how it goes first ;)
:)
slm
slm
can i get some of that popcorn?
@terdon I don't understand the difference.
slm
slm
Mar 14, 2014 02:59
See it was the use of run
@slm sorry, edited
slm
slm
LOL can you give me the link to what A we're talking about?
@slm probably
@slm All that bugged me about it was that it said something I thought might be misinterpreted to wind up with someone's shit getting deleted.
@strugee And no, not a lawyer. I was an Army helicopter mechanic.
@mikeserv it was @slm that asked. not me.
slm
slm
Mar 14, 2014 03:01
I asked what you did
@strugee my bad. Like I said - this keyboard sucks.
slm
slm
why is your username mikeserv?
if I may ask
@slm my bad. Like I said - this keyboard sucks.
@mikeserv the difference as I understand it (and my understanding is quite limited, I'll be the first to admit) is that a script is run as a, well, a script. With it's own subshell and PID. While sourcing will simply read the commands in the other file and incorporate them into the script doing the sourcing. Kinda like #includes for C as slm said before.
Yea, when I hear the phrase "runs another script" I can only interpret that as a spawned process with its own PID, and I cannot reconcile that with what source does.
slm
slm
Mar 14, 2014 03:04
read(3, "#!/bin/bash\n\n. somefile.txt\n", 80) = 28
that's from an strace, it's just reading the file in, not running it
@slm I was - and guess I still am - a geek as a kid. My cousin had an ISDN line IRC server, and broadband internet had just come out and you didn't get DHCP addresses then, we got static IPs when my dad hooked up DSL. So my cousin asked me to share the load, and I took mikeserv, alongside operserv and the rest of the bots. Don't know why, my name's Frank.
slm
slm
good story
open("somefile.txt", O_RDONLY) = 3
@slm I consider that thinking fallacious, because the shell does that, probably, but it's not guaranteed and is usually a result of the hash bang. No hash bang, and you might not have a new process at all.
@mikeserv huh? Really?
slm
slm
frank it doesn't matter what we think, that's what the computer is doing
Mar 14, 2014 03:06
@slm As far as I know, that's implementation dependent. And besides, I'm pretty sure you can get the exact same behavior with . .
slm
slm
I just showed output from an strace
@slm . a #!/bin/dash file.
slm
slm
that isn't what I did there
@slm My name really is Mike, by the way.
slm
slm
Mar 14, 2014 03:08
$ more somefile.txt
echo "hi mike"
echo "sam sourced this"
$ more somescript.bash
#!/bin/bash

. somefile.txt
OK>?
franike
That wont work.,
. ./somefile.txt
slm
slm
pretend I'm your math teacher, show your work
@mikeserv why not? He just showed you the strace output of exactly how that works. Incidentally, the same output clearly demonstrated that one is executed and the other is read as a text file.
casey@convect ~ % cat test3.sh
#!/this/path is garbage.
print This statement is being executed
casey@convect ~ % . ./test3.sh
This statement is being executed
slm
slm
He's not going to buy it
Mar 14, 2014 03:11
casey@convect ~ % ./test3.sh
zsh: ./test3.sh: bad interpreter: /this/path: no such file or directory
slm
slm
come on man put it together
Did we hit 88 miles per hour in the Delorian?
@terdon - still wanting that flame war?
@slm yeah, see, I'm prescient!
casey@convect ~ % cat test4.sh
#!/usr/bin/python2 -V
print test
casey@convect ~ % . ./test4.sh
test
casey@convect ~ % ./test4.sh
Python 2.7.5
@casey just... wow
I always knew I was special. My mom told me when I was but a lad.
@casey very nice!
Mar 14, 2014 03:15
echo "current shell $0" ; printf %s\\n '#!/usr/bin/dash' 'echo script shell '\$0 >~/somefile.txt
; . ~/somefile.txt
current shell -/usr/bin/zsh
script shell /home/mikeserv/somefile.txt
@Braiam @terdon thanks. I had a vision...
@casey This didnt work because . is not ./
@Braiam ./test3.sh That one I mean
@mikeserv no, it worked exactly as it should have
@mikeserv he used ./ to execute the script and . to source it
@casey Not according to this: casey@convect ~ % ./test3.sh
@terdon The directory link ./ is not the shell builtin .
Mar 14, 2014 03:19
@mikeserv just how you think he should do it?
test3 and test4 demonstrate the hashbang is ignored because the shell is interpreting the contents itself and not spawning the interpreter as another process
and I did both . and ./ to show the difference
@casey . ./
Oh, well, like I said I only think that can be done. Mine worked though - at least for $0.
@mikeserv em, yes, exactly. But he just used ./ when executing, note that he wrote . ./foo.sh
@mikeserv but that's exactly what he did!
. ./file <- . is the builtin, and ./file is a relative path to a filename
Ok, I was looking at my shell doing the other thing and just saw a zsh error.
Besides I think that's implementation dependent anyway, but I'm not sure.
Mar 14, 2014 03:21
here it is again, both ways together
casey@convect ~ % . ./test3.sh
This statement is being executed
casey@convect ~ % ./test3.sh
zsh: ./test3.sh: bad interpreter: /this/path: no such file or directory
@casey exactly that.
@mikeserv give us some credit "dude". You'd think the regulars on a site like this might just be aware of what ./ means!
@casey Ok, I get it now. So it didn't take its hash bang. I didn't, til I read it.
yes, because it is not a valid script, but it does contain some valid statements that zsh can parse
which is why sourcing it works
slm
slm
sourcing views it as a comment
Mar 14, 2014 03:23
exactly
I dunno, it only came up because slm used this as proof it didn't work. $ more somescript.bash
#!/bin/bash

. somefile.txt
OK>?
franike
which i thought the python demonstrated quite well
slm
slm
read up on how shebang works too
In computing, a shebang (also called a sha-bang, hashbang, pound-bang, hash-exclam,), is the character sequence consisting of the characters number sign and exclamation mark (that is, "#!") at the beginning of a script. Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script. For example, if a script is named with the path "...
Yeah, what was that about "No hash bang, and you might not have a new process at all."?
without a hashbang you should get a new process but the same interpreter
slm
slm
Mar 14, 2014 03:26
the hashbang is a magic number
yep
PSA: Shog said what is an answer:
12
Q: Your answer is in another castle: when is an answer not an answer?

Shog9I think we can all agree, this sucks: If you've been around a little while, you've probably encountered hundreds of answers like this in various forums, some of them even marked as "The Answer" by well-meaning* forum admins looking to close a thread. We could try to enumerate the commonly-obse...

Ok, now some others need the arrow.
slm
slm
The shebang is actually a human-readable instance of a magic number in the executable file, the magic byte string being 0x23 0x21, the two-character encoding in ASCII of #!. This magic number is detected by the "exec" family of functions, which determine whether an image file is a script or an executable binary.
@mikeserv scrolling back that far is pretty hard
Mar 14, 2014 03:29
@casey It is on the tv, yeah.
Sorry
But I didn't know if I was being asked a question or if you guys were talking to each other.
@mikeserv I think its safe to say the validity of that statement was called into question.
slm
slm
"which determine whether an image file is a script or an executable binary." This last bit would seem to imply that a file with commands in it is neither
@casey Which statement? That . might interpret a hash bang depending on implementation?
I think so too.
No, the "No hash bang, and you might not have a new process at all."? statement
see this:
casey@convect ~ $ cat test5.sh
echo pid = $BASHPID
casey@convect ~ $ echo $BASHPID
28589
casey@convect ~ $ . ./test5.sh
pid = 28589
casey@convect ~ $ ./test5.sh
pid = 28915
no hashbang, but executing it (not sourcing it) results in a subshell in a new process.
Did I say that? Yeah, I think that's wrong. But sourcing it does execute it. And all the sourced script needs to do is exec out, or if it wants a subshell it just ( asks ) for one.
Mar 14, 2014 03:38
@mikeserv . by definition cannot interpret a hashbang, because to do so requires spawning a process via exec and then you are no longer executing the following statements in the current shell
I would be very surprised to see another (non POSIX) implementation of source
In any case it's definitely executed - that's it's definition.
33 mins ago, by mikeserv
@slm I consider that thinking fallacious, because the shell does that, probably, but it's not guaranteed and is usually a result of the hash bang. No hash bang, and you might not have a new process at all.
NAME

dot - execute commands in the current environment
no one is arguing that as far as I'm aware?
What was the next statement I made?
That was what I spent first 30 minutes here debating.
slm
slm
Mar 14, 2014 03:40
what are you arguing about now?
Anyway, my tests stand on their own... interpret them as you wish
slm
slm
i left to help other ppl w/ questions
@slm same
slm
slm
this is turning into a waste of time
ask a Q on the site if you have one framike
Changing the subject, I've been playing around on an Ubuntu VM this week. Does this look familiar to anyone?
 
Conversation ended Mar 14, 2014 at 3:41.