LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   having trouble building an array in AIX. Works in Linux (https://www.linuxquestions.org/questions/linux-general-1/having-trouble-building-an-array-in-aix-works-in-linux-4175659082/)

unix1adm 08-13-2019 01:34 PM

having trouble building an array in AIX. Works in Linux
 
I have a script that works fine in Linux Specifically Red hat.

However when i go to run it in AIX it gets an error

Not sure if the correct place to put this question.

Any help is appreciated.



# Retrieve and format the system date/time appropriately
datetime=$(date "+%D %r")

# Enumerate users and non-empty groups on the system
for username in $(cat /etc/passwd | awk '/^#/{next}1' | cut -d: -f1); do
# Search for users in primary groups and append to array
userprimarygroupid=$(grep ^$username /etc/passwd | awk '/^#/{next}1' | cut -d: -f4)
userprimarygroupname=$(grep ":$userprimarygroupid:" /etc/group | awk '/^#/{next}1' | cut -d: -f1)
outputarr+=( ""$userprimarygroupname"",""$username"",""Local User"",""$datetime"")
# Search for users in secondary groups and append to array
for usersecondarygroupname in $(grep $username /etc/group | cut -d: -f1); do
outputarr+=( ""$usersecondarygroupname"",""$username"",""Local User"",""$datetime"")
done
done

# Write Results to stdout for mgmt systems to retrieve
printf '%s\n' "${outputarr[@]}" | sort -u


---------------------

error

./localgroup.sh[6]: 0403-057 Syntax error at line 10 : `(' is not expected.

scasey 08-13-2019 01:39 PM

Please use [code] tags when posting code. It makes it much more readable.

Please tell us which line is line 10 of the script. Maybe highlight it?
If it's this line
Code:

for username in $(cat /etc/passwd | awk '/^#/{next}1' | cut -d: -f1); do
I believe the $(command) construct is a bash-ism.

What shell is being used on the RH machine?
What shell on the Unix box?

TB0ne 08-13-2019 01:52 PM

Asked this in the OP's duplicate thread: https://www.linuxquestions.org/quest...ix-4175659081/

OP has also been asked several times over the past ELEVEN YEARS, to use code tags, and not post duplicates.

Reported

unix1adm 08-13-2019 02:03 PM

My apologies for the code tags I was entering this in a hurry. The other forum look dead. No posts in a long time so I thought I would try here.

Would yo be so kind as to point me to a link that shows me how to use code tags in this forum.

TB0ne 08-13-2019 02:10 PM

Quote:

Originally Posted by unix1adm (Post 6024789)
My apologies for the code tags I was entering this in a hurry. The other forum look dead. No posts in a long time so I thought I would try here.

Would yo be so kind as to point me to a link that shows me how to use code tags in this forum.

You've been here ELEVEN YEARS, and never used CODE tags, despite being asked, so the 'in a hurry' response kind of falls flat, especially since you've used it before.
https://www.linuxquestions.org/quest...5/#post5852069

And the LQ Rules are very clear about posting duplicates as well. There are icons on the posting window...did you try putting your mouse over them, and looking at the tool-tips? Specifically the # character???

unix1adm 08-13-2019 02:18 PM

I sincerely apologize and did not mean to raise anyone's blood pressure over this. i have not been posting for some time

I will gladly close this duplicate out.

As I said the other forum had no posts for over 100 days and I was not sure which forum to post under.
Thank you fro your kind words of advice

scasey 08-13-2019 02:23 PM

Quote:

Originally Posted by unix1adm (Post 6024789)
My apologies for the code tags I was entering this in a hurry. The other forum look dead. No posts in a long time so I thought I would try here.

Would yo be so kind as to point me to a link that shows me how to use code tags in this forum.

Sure. There's a link at the bottom of every page: "BB code"
If you hover your mouse over the tools at the top of the posting window, you'll find the one that says "Wrap [CODE] tags around selected text"


Now will you answer the questions in #2?

onebuck 08-13-2019 03:47 PM

Moderator Response
 
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate of https://www.linuxquestions.org/quest...ix-4175659081/


All times are GMT -5. The time now is 01:37 PM.