LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2011, 12:55 PM   #1
pr0tocoldan
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Rep: Reputation: Disabled
NSH Shell Scripting Question


I'm writing a script and I have doubts on how to assign values to an already established variable. The value for the vatriable would be coming from a file with three columns. I'm using the awk command for this. Am I doing it correctly? which of the following two ways is the better one or if both are wrong which one should I use?

#!/bin/nsh

inputfile=$1
rolename=$2
roleauthprofile=$3
userid=$4

Option 1:
or properties in 'cat $inputFile'
do
awk '{grep $1=$rolename}'| awk '{grep $2=$roleauthprofile}'|awk '{grep $3=$userid}'

Option 2:
awk '{export $1=$rolename}'| awk '{export $2=$roleauthprofile}'|awk '{export $3=$userid}'
echo $rolename
echo $roleauthprofile
echo $userid

I appreciate your help.

Regards,

pr0tocoldan
 
Old 06-24-2011, 09:47 PM   #2
pr0tocoldan
LQ Newbie
 
Registered: Jun 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
for properties in 'cat $inputfile'
do
rolename = cat $inputfile : awk {print $1}
roleauthprofile= cat $inputfile : awk {print $2}
userid = cat $inputfile : awk {print $3}
 
Old 06-24-2011, 09:51 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I don't know Nsh but if it's similar to Bash / Bourne Shell (just change the first line to test) then here's a wee example assigning variables. Asserting the input file has space separated values you test if the file exist (else just exit cleanly), cat it and use readline to set values and echo them. Assigned values exist inside the "while" loop and you can do anything with it there.
Code:
#!/bin/sh
test -f "$1" && cat "$1" | while read NAME PROFILE USERID; do
 echo "$NAME $PROFILE $USERID"
done
exit 0

Code:
function shellhelp() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/; }
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting question creolophus Linux - Software 1 10-02-2006 02:13 AM
shell scripting question JSLayton Linux - General 4 06-01-2006 06:55 AM
Shell scripting question. dragin33 Linux - General 2 08-11-2004 05:17 PM
Shell Scripting Question Onyx^ Linux - General 5 04-27-2004 10:37 AM
Shell Scripting Question jester_69 Programming 13 11-05-2003 06:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration