Results 1 to 5 of 5
I'm new to scripting although I did have some programming classes a couple of years ago. I trying to make a very simple addusers bash script. I am trying to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-11-2005 #1Just Joined!
- Join Date
- Apr 2005
- Posts
- 2
Simple add users script from text file
I'm new to scripting although I did have some programming classes a couple of years ago. I trying to make a very simple addusers bash script. I am trying to read from a file that has a list of usernames their fullnames. Their username and fullname are separated by a comma with the next person on a new line. I know that can get what the value I want from a command line with this: y=$(wc -l /root/user.txt | awk -F/ '{print}') . I just am unsure on how to tie this to a variable. I am getting an error of too many arguements when I run the script. Any links on where to learn more on how to do this would be very much appreciated too.
Actually I'm having specfic trouble understanding two things, even though I figured how to make it run right.
Why when I am using a counter do I need to use let (var) instead of just a straight equality statement to get my desired result?
let x=[$x+1] instead of x=[$x+1]
and what is the difference between
y=$(wc -l /root/user.txt | awk -F/ '{print}')
and
y='wc -l /root/user.txt | awk -F/ '{print}''
- 04-11-2005 #2do you mean `wc etc...` because `` and $() are the same thing. as to the first error, can you elaborate?and what is the difference between
y=$(wc -l /root/user.txt | awk -F/ '{print}')
and
y='wc -l /root/user.txt | awk -F/ '{print}''
- 04-11-2005 #3Just Joined!
- Join Date
- Apr 2005
- Posts
- 2
when is use: x=[$x+1]
the value of x would literally be 1+1
if I use: let x=[$x+1]
I get the desired result of it counting up
I guess I don't see why the first way doesn't work.
- 04-11-2005 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Re: Simple add users script from text file
I don't use square brackets much myself, but the obvious answer is that the let version is treating x as an integer, whereas the plain "x=" version is treating it like a string. I'd have used "x = expr $x + 1" myself, but I'm kinda old-fashioned.
Originally Posted by a_kerbouchard
Are you using backticks to surround the wc -l ... print}'? On my screen they look like ordinary single quotes. The first version is preferrable because it enables you to nest commands with having to worry about escaping nested backticks. I'm not sure why you're piping wc's output to awk, the quickest way to just get the number from wc is to use echo and stdin:and what is the difference between
y=$(wc -l /root/user.txt | awk -F/ '{print}')
and
y='wc -l /root/user.txt | awk -F/ '{print}''
y=$(echo $(wc -l </root/user.txt))
This also demonstrates nested commands.
Steve
- 04-12-2005 #5Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
What value are you trying to get ?
Originally Posted by a_kerbouchard
But this in a loop would be many times slower than using
Originally Posted by scm
built-in arithmetic.


Reply With Quote
