Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to define multiple environment variables in a shell script? Post 303045887 by RudiC on Friday 17th of April 2020 02:49:52 AM
Old 04-17-2020
Quote:
Originally Posted by sravani25
.
.
.
Code:
abc=$(find $config_path -name xyz.xml 2>/dev/null)
 user_name=$(cat $abc |grep username )
export NAME=$user_name

when i executed the shell script it's executed successfully but when i am trying to print the environment variable it's returning empty value
echo $NAME -- is giving empty value.

$NAME being empty is a strong indicator that $user_name is empty and the "command substitution" fails / results in an empty string. I guess its because the file called $abc doesn't exist. and the cat cats nothing.



Quote:
Can you please let me know what i need to change to set the environment variable ?
It would help if people knew the entire scenario. Variables in which environment do you want to set? Your current session? Future sessions? Why the echoing into the varying .profiles?
 

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
setenv(3C)																setenv(3C)

NAME
setenv(), unsetenv() - add, update or remove an environment variable SYNOPSIS
Parameters envname Points to a string containing the name of an environment variable to be added or altered. This should not be a NULL pointer or null string, and the string should not contain an equal character. envval Points to a string containing the value to be set for the variable envname. overwrite Indicates whether to overwrite the value of envname variable or not, if it already exists. Expected values are non-zero and zero. If the environment variable does not exist in the environment, then the value of this variable is ignored. DESCRIPTION
and functions update the environment of the calling process. If envname does not exist, the function ignores the value of overwrite and adds the variable envname to the environment with the value envval. If envname exists and overwrite is non-zero, then the variable envname is updated with the new value envval. If envname exists and overwrite is zero, then the variable is not updated, and the function is considered to have completed successfully. The function deletes the variable envname from the environment, if it exists. If the envname variable does not exist in the current envi- ronment, the environment is unchanged, and the function is considered to have completed successfully. If the application modifies environ or the pointers to which it points, the behavior of and is undefined. EXTERNAL INFLUENCES
Locale The category determines the interpretation of characters in string as single- and/or multi-byte characters. International Code Set Support Single- and multi-byte character code sets are supported. RETURN VALUE
The and functions return zero on success; otherwise they return and set to indicate the error. ERRORS
If the function fails, is set to one of the following values: Sufficient memory is not available to add a variable or its value to the environment. The envname argument is a null pointer, points to an empty string, or points to a string containing an equal character. If the function fails, is set to the following value: The envname argument is a null pointer, points to an empty string, or points to a string containing an equal character. EXAMPLES
The following code adds a new environment variable to the current environment. The following code updates the variable The following code removes the variable from the current environment. WARNINGS
The and functions manipulate the environment pointed to by environ, and can be used in conjunction with However, envp (the third argument to main) is not changed. The uses to enlarge the environment (see malloc(3C)). After the or function is called, environment variables may not be in alphabetical order. AUTHOR
and were developed by HP. SEE ALSO
exec(2), getenv(3C), malloc(3C), putenv(3C), environ(5), thread_safety(5). STANDARDS CONFORMANCE
setenv(3C)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy