| Blogs | Classifieds | Downloads | FlashChat | Gallery | Googlemap | Invite Friends | Links | Projects | Reviews | Wiki |
| |||||||||
Welcome to the pSeries Tech Forums,
our free peer-based support site for administrators, engineers and architects working with IBM pSeries servers and software. You are currently viewing our site as a guest which gives you limited access to view most discussions, articles, tutorials and access our other free features. By joining our community you will be able to collaborate with administrators, engineers and architects charged with designing, delivering or maintaining IBM pSeries server environments. Founded by a recognized IBM pSeries consultant and IBM Redbook author, pSeries Tech Forums was developed with the single mission of bringing IBM pSeries professionals together into a single self-help community. Registration is fast, simple and absolutely free to all IT professionals with responsibility for or interest in IBM pSeries servers. We invite you to join our community today! If you have any problems with the registration process or your account login, please contact contact support. |
| Our Sponsors | |
| | |
| Want to advertise? | |
![]() |
| | LinkBack | Thread Tools |
|
#1
| ||||
| ||||
I want to write a script in KSH that uses another file as a config file to read in variables. Can somebody help me out and maybe provide some code I can work off of. Lets say a script called 'program' needs a file called 'config' that contains the lines... FTP=123.123.123.123 USER=AIX PASS=RULEZ ...I would need to read those lines into 'program' and assign them as variables within 'program'. Thanks. |
|
#2
| ||||
| ||||
config FTP=123.123.123.123 USER=AIX PASS=RULEZ a.ksh #!/bin/ksh . ./config echo "The value of FTP is: $FTP" echo "The value of USER is: $USER" echo "The value of PASS is: $PASS" That should get you want you want. The key line here is the . ./config, which tells the script to source the file named config. By default, any changes made to your environment only affect the process you are currently in, and not the parent process environment. This causes issues since you want to run a script (config in this case) to set environment variables. The process of running the config script from the a.ksh script causes the config script to run as a child of the a.ksh script, and thus any changes to the environment that the config script does, only affects it's own process environment, and not that of the parrent (a.ksh). By sourceing the config script with the leading period, changes made to the environment are done in the parent process. Now, I see that you are wanting to have FTP credentials for an automated FTP script or something similar. Do a man on ftp, and search for .netrc. The .netrc file allows you to specifiy FTP credentials for use in automatic FTP logins. Hope this helps, Dave |
|
#3
| ||||
| ||||
In "program" include the following line to source the config file. Note the period at the beginning of the line. The variables should then be set for the program to use. . /some-directory/config |
|
#4
| ||||
| ||||
Quote:
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |