help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] GNU bash, version 4.4 – A valid command is not performe


From: Greg Wooledge
Subject: Re: [Help-bash] GNU bash, version 4.4 – A valid command is not performed
Date: Tue, 11 Dec 2018 09:08:23 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Dec 11, 2018 at 01:21:14PM +0100, Ricky Tigg wrote:
> $ cat users_groups
> #!/usr/bin/env bash
> 
> declare -A groups=(
>     ["test_user"]="wheel,users"
> )

It is not clear where the file ENDS.  Is this the end of the file, after
the array definition?  Are the following lines separate?

> $ sudo su
> # pwd
> /home/yk
> 
> The following command purpose is to create users and add them to groups.
> 
> # for user in "address@hidden"; do useradd -U -G "${groups[$user]}" "$user";
> done < users_groups
> #

If my assumption about the length of the file are correct, then what
you are doing here is feeding a shell script as input to this for
loop.  However, the loop does not actually *read* the file.  (Which is
probably a good thing, since you did not write any code to parse a
shell script.  Nor should you.  That would be extremely ill-advised.)

I believe that what you want to do is source the file, which will create
an array within your interactive shell.  And then your for loop will
be able to iterate over that array, and so on.

$ sudo -i
# source ./users_groups
# for ... done



reply via email to

[Prev in Thread] Current Thread [Next in Thread]