[CS] UNIX

Forum van 1ste Bachelor Informatica.

Moderator: Praesidium

User avatar
Norfolk
WOZ
Posts: 780
Contact:

UNIX

Post#1 » Thu Jan 05, 2006 2:36 pm

Bij variabelen staat in de slides het volgende:
Use export to export variables from parent shell to shell executing the script
Use ‘. ./myScript.sh’ to ‘source’ the script.
Weet iemand wat dit juist doet?
Last edited by Norfolk on Thu Jan 05, 2006 3:08 pm, edited 1 time in total.

User avatar
j0lle
WOZ
Posts: 396

Post#2 » Thu Jan 05, 2006 2:47 pm

export is simpelweg een variabel in een script beschikbaar maken buiten het script (zie het wa als een globale variabele, maar dan over heel u systeem)


u script sourcen is ook zoiets.. ma das moeilijk om uit te leggen..
ge runt u script meestal IN ne 'subshell', en uwe parent shell (waar gij in werkt) leest standaard niks uit u programma zoals procedures en variabelen. maar door u script te sourcen maakt ge da wel beschikbaar. khoop da't wa duidelijk is :p


edit: beste uitleg da'k kan vinden

Code: Select all

When you run a script it is normally invoked in a subshell, meaning
the variables, functions, shell options, and ALIASES you define in the
script are not seen by the parent shell ( the shell from which you
executed the script ). You can execute your script as a "dot" script
to cause it to be executed in the current shell as follows:

. ./MyScript.sh

User avatar
Norfolk
WOZ
Posts: 780
Contact:

Post#3 » Thu Jan 05, 2006 3:15 pm

XenoPhobian wrote:u script sourcen is ook zoiets.. ma das moeilijk om uit te leggen..
ge runt u script meestal IN ne 'subshell', en uwe parent shell (waar gij in werkt) leest standaard niks uit u programma zoals procedures en variabelen. maar door u script te sourcen maakt ge da wel beschikbaar. khoop da't wa duidelijk is :p
subshell is da vensterke waar ge in typt en parent shell heel uw systeem ofwa?

Kheb het precies wel gevonden in praktijk:
hello.ksh:

Code: Select all

#!/usr/bin/bash
test="Hello Olivier"
test.ksh:

Code: Select all

#!/usr/bin/bash
test="testje"
./hello.ksh
echo $test
Als ik daar die ./hello.ksh zo laat staan print die laatste "testje" af.
Als ik daar . ./hello.ksh daar zet, print die "Hello Olivier" af.
Is het dat wat je bedoelt?

User avatar
j0lle
WOZ
Posts: 396

Post#4 » Thu Jan 05, 2006 3:27 pm

idd
en nu bijkomende vraag van mij: is die variabele "test" nu overscreven als ge 'gesourced' hebt?
en waarom extension van kshell gebruiken? :-)

User avatar
EagleEye812
Posts: 406

Post#5 » Thu Jan 05, 2006 3:48 pm

tis zoals bij programmere die lokale/globale variabelen.. all over again :P

User avatar
Norfolk
WOZ
Posts: 780
Contact:

Post#6 » Thu Jan 05, 2006 4:09 pm

XenoPhobian wrote:idd
en nu bijkomende vraag van mij: is die variabele "test" nu overscreven als ge 'gesourced' hebt?
en waarom extension van kshell gebruiken? :-)
ksh: kweni, da staat in slides. Normaal deed ik da ook ni maar bij aanmaken van deze is gedaan.

is volgens mij wel overschreven?
Want als ge . ./hello.ksh doet dan roept ge dat script op. Dus tegen mijn echo begint, is dat script al gedaan en dus test is overschreven.
Als ik nu ./hello.ksh doet dan zal hij zolang dat script loopt test op Hello Olivier zetten, maar na script terug gewoon zetten.
Niet? :P

User avatar
Shinta
WOZ
Posts: 1122

Post#7 » Thu Jan 05, 2006 6:14 pm

bij mij runt dattan gewoon alskik . ./piemel.sh doe, anders doetta nix, buh

User avatar
Norfolk
WOZ
Posts: 780
Contact:

Post#8 » Thu Jan 05, 2006 7:07 pm

Shinta wrote:bij mij runt dattan gewoon alskik . ./piemel.sh doe, anders doetta nix, buh
het begint met p en eindigt met iemel :D
Ok da was ander topic...

ja als ge da gewoon oproept in uw raampke dan ziede geen verschil...

Return to “1ste Bachelor”

Who is online

Users browsing this forum: No registered users and 1 guest

cron