Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to define multiple environment variables in a shell script? Post 303045906 by sea on Friday 17th of April 2020 04:11:02 PM
Old 04-17-2020
You're using find to search directories, nice.
But then you're using the variable without checking if it's has one , none or more results.

Further, I assume that you want the variable $user_name to actualy contain (just) the "<username>", and not the string "username + <username>".
This said, you might want to take care of that, afterwhich you might want to use something like this:
Code:
if [[ -n "$user_name" ]]
then    export NAME=$user_name
else    echo "<user_name> is empty"
        # If it is within a script:
        #exit 1
fi

As the string might become empty after removing the found string pattern from it's content ("username + <username>"), if it even finds anything - as in your current case.
This said, you might want to make sure where your find starts from.

I would also suggest to take care of multiple finds (tempfiles) within a a for loop.
This is my suggested handling for all dynamic (find, locate, *, ls, which, etc) variables.

Hope this helps

Last edited by sea; 04-17-2020 at 05:18 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script help: sorting, incrementing environment variables and stuff

First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info. I'm writing a shell script to automate the setup of a flash 'page flip'. My current code is below. the page flip takes an xml file of format <content> <pages... (1 Reply)
Discussion started by: secoif
1 Replies

2. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

3. Emergency UNIX and Linux Support

Problem setting environment variables from script

Hi all! I know that environment variables can be set on the .bashrc file, but I need to set them from a sh script. I saw a lot of websites that teach this but it doesn't work for me. #!/bin/sh DEKTOP=$DESKTOP=:/home/rrodrigues/Desktop export DESKTOP if I do echo $DESKTOP returns me... (10 Replies)
Discussion started by: ruben.rodrigues
10 Replies

4. UNIX for Dummies Questions & Answers

Define variables with UNIX script

oopps! I Meant "Define Variables within a UNIX Script" What would be the best way to define a variable in a unix shell script so anyone who views this script doesn't know what value is assigned to that variable. some other location... a="/usr/lib/fileA" Unix script... sed... (5 Replies)
Discussion started by: macastor
5 Replies

5. Shell Programming and Scripting

environment variables in a sed script file

Hello Everyone I need to create a script file which must append some lines to a target text file, I'm using sed for windows, the script file look like this: { a\ STRINGTABLE DISCARDABLE\ BEGIN\ 5, 150 {a\ #define RC_SHELL, "%ID_SHELL%"\ #define RC_NAME, "%ID_NAME%"\ END } ... (1 Reply)
Discussion started by: edgarvm
1 Replies

6. Shell Programming and Scripting

Using Datastage environment variables in Unix script

Hi All, I am using ETL tool Datastage and is installed on Linux environment. Few environment variables are set in datastage. Now my requirement is to use those environment variables in a unix script. Is there any option I can do it? Sugeestions from people working on datastage and linux... (1 Reply)
Discussion started by: bghosh
1 Replies

7. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

8. Shell Programming and Scripting

Sourcing .cshrc (C shell) environment variables to bash

I have tried with the following: csh -c 'source ~/.cshrc; exec bash' # works perfectly (cat ~/.cshrc; echo exec bash) | csh # not working And, using sed, I successfully retrieved the environment variables from ~/.cshrc sed -rn 's/setenv\s+(\S+)\s+(.*)$/export \1=\2/p' ~/.cshrc but now... (6 Replies)
Discussion started by: royalibrahim
6 Replies

9. Linux

How to store count of multiple queries in variables in a shell script?

how to store the count of queries in variables inside a filein shell script my output : filename ------- variable1=result from 1st query variable2=result from 2nd query . . . . (3 Replies)
Discussion started by: sanvel
3 Replies

10. Shell Programming and Scripting

How to define two digits variable in shell script?

Dear Shell script Experts, I am working on shell script which is defined here, qsub_seq.csh . The purpose of this script is to read few input files (with defined starting index and last index) and make processing faster over server. For some task, I had 1064 of input files, so I wrote another... (8 Replies)
Discussion started by: emily
8 Replies
GROUPMEMS(8)						    System Management Commands						      GROUPMEMS(8)

NAME
groupmems - administer members of a user's primary group SYNOPSIS
groupmems -a user_name | -d user_name | [-g group_name] | -l | -p DESCRIPTION
The groupmems command allows a user to administer his/her own group membership list without the requirement of superuser privileges. The groupmems utility is for systems that configure its users to be in their own name sake primary group (i.e., guest / guest). Only the superuser, as administrator, can use groupmems to alter the memberships of other groups. OPTIONS
The options which apply to the groupmems command are: -a, --add user_name Add an user to the group membership list. If the /etc/gshadow file exist, and the group has no entry in the /etc/gshadow file, a new entry will be created. -d, --delete user_name Delete a user from the group membership list. If the /etc/gshadow file exist, the user will be removed from the list of members and administrators of the group. If the /etc/gshadow file exist, and the group has no entry in the /etc/gshadow file, a new entry will be created. -g, --group group_name The superuser can specify which group membership list to modify. -h, --help Display help message and exit. -l, --list List the group membership list. -p, --purge Purge all users from the group membership list. If the /etc/gshadow file exist, and the group has no entry in the /etc/gshadow file, a new entry will be created. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. SETUP
The groupmems executable should be in mode 2770 as user root and in group groups. The system administrator can add users to group groups to allow or disallow them using the groupmems utility to manage their own group membership list. $ groupadd -r groups $ chmod 2770 groupmems $ chown root.groups groupmems $ groupmems -g groups -a gk4 CONFIGURATION
The following configuration variables in /etc/login.defs change the behavior of this tool: MAX_MEMBERS_PER_GROUP (number) Maximum members per group entry. When the maximum is reached, a new group entry (line) is started in /etc/group (with the same name, same password, and same GID). The default value is 0, meaning that there are no limits in the number of members in a group. This feature (split group) permits to limit the length of lines in the group file. This is useful to make sure that lines for NIS groups are not larger than 1024 characters. If you need to enforce such limit, you can use 25. Note: split groups may not be supported by all tools (even in the Shadow toolsuite). You should not use this variable unless you really need it. FILES
/etc/group Group account information. /etc/gshadow secure group account information SEE ALSO
chfn(1), chsh(1), passwd(1), groupadd(8), groupdel(8), useradd(8), userdel(8), usermod(8). shadow-utils 4.1.5.1 05/25/2012 GROUPMEMS(8)
All times are GMT -4. The time now is 05:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy