Another 10 second question. Assigning 2 strings to one string.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another 10 second question. Assigning 2 strings to one string.
# 1  
Old 09-07-2007
Another 10 second question. Assigning 2 strings to one string.

Hi, I am trying to combine 2 strings into one new string. I know there are existing threads on this topic, but I am having troubles. The variables have variables within their names which is causing me problems. Bad subsitution is the error.

The problem line is in red below.

thanks (again) to all that can help!

##!/bin/bash
## userprocesses

nousers=$( who | wc -l )
usercnt=1 # counter used in setup
pos=1
userout=1

who -q | sort -d > tempA
set -- $( cut -f "$pos" tempA);

##Put usernames into TempA
while [ $usercnt -le $nousers ]
do
eval user${pos}=$1
shift
usercnt=$(( $usercnt + 1 ))
pos=$(( $pos + 1 ))
done
rm tempA; > tempA;
namecnt=1
while [ "$namecnt" -le "$nousers" ]
do
grep $user${namecnt} /etc/passwd | cut -d: -f5 >> tempA
namecnt=$(( $namecnt + 1 ))
done

##getting real names
set -- $( cut -f1 tempA )
shiftcnt=1
while [ $shiftcnt -le 15 ]
do
shift
shiftcnt=$(( $shiftcnt + 1 ))
done

count1=1
while [ $count1 -le $nousers ]
do
eval realfirstname${count1}=$1
shift
count1=$(( count1 + 1 ))
done

intA=1
intB=2
while [ $intA -le $nousers ]
do
eval realname${intA}= [${realfirstname${intA}}]${realfirstname${intB}}]

intA=$(( intA + 2 ))
intB=$(( intB + 2 ))
done
echo "$realname1"
# 2  
Old 09-07-2007
hmmm

I have just combined the two using:

eval realname1= ${realfirstname1}${realfirstname2}

this is part of the way, but i need the 1 and 2 at the end of those variables to be represented by intA and intB.

I have an error, line 50: 'users real name': command not found

I have not issued a command, other than to assign it to the new variable.

Help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script stops running after assigning empty string for a variable

Hi, This is the first time I see something like this, and I don't why it happens. Please give me some help. I am really appreciate it. Basically I am trying to remove all empty lines of an input.. #!/bin/bash set -e set -x str1=`echo -e "\nhaha" | grep -v ^$` #str2=`echo -e "\n" |... (4 Replies)
Discussion started by: yoyomano
4 Replies

2. UNIX for Advanced & Expert Users

couting occurences of a character inside a string and assigning it to a variable

echo "hello123" | tr -dc '' | wc -c using this command i can count the no of times a number from 0-9 occurs in the string "hello123" but how do i save this result inside a variable? if i do x= echo "hello123" | tr -dc '' | wc -c that does not work...plz suggest..thanks (3 Replies)
Discussion started by: arindamlive
3 Replies

3. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

4. UNIX for Dummies Questions & Answers

Assigning String to Arrays

Hello everybody, this is my first post here, I think IŽll be here for a long time :D I wanted to know how I can assign each single character from a string to an array... For example, "unix" I have to set, array=u array=n array=i array=x However, that string may change in each... (5 Replies)
Discussion started by: Gartlar
5 Replies

5. Shell Programming and Scripting

Problems assigning a string to a variable

Hello everyone, My problem looks quite simple , how to assign a string with spaces and lines "\n" to a variable. I've tried all kind of quoting and is impossible, bash always try to execute the string and never executes a simple assignation. This is part of the code ... (1 Reply)
Discussion started by: trutoman
1 Replies

6. Shell Programming and Scripting

Quick UNIX question - Assigning a word to $model

When the following is typed: /usr/platform/`uname -i`/sbin/prtdiag | awk '{print $7; exit}' ...the output I get back is either "X4150" or "X4170" when executed on a Sun Fire X4150 or X4170. ---But, may I ask how do I assign the variable $model to it? Because of the embedded backquotes, I... (3 Replies)
Discussion started by: chatguy
3 Replies

7. Shell Programming and Scripting

simple assigning variable question

I know many will probably say go read some tutorials...I would like to say that I am. However, I need to know this for work and it needs to be done soon. In my script I have a while loop that reads a .tbl file of 4 columns and assigns them to variables a, b, c, d. Once in the loop i do ... (10 Replies)
Discussion started by: questionasker
10 Replies

8. Shell Programming and Scripting

retreiving and assigning values and manipulating string in a for loop

Hi I am new to shell scripting and i am preparing a script. for now i am work on a sub part of it..but i am unable to make it work. --- the test code that i am working on -------------------------- IFS="" Sample_eve=`psg proc_s | grep tY` n=0 for line in $Sample_eve... (41 Replies)
Discussion started by: Anteus
41 Replies

9. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

10. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies
Login or Register to Ask a Question