Whats does this export command do?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Whats does this export command do?
# 1  
Old 04-11-2011
Whats does this export command do?

Hi,
I know that export command is used to set environment variable.

Can you please explain what ":--100" in the below command is doing?

Code:
export ROWSTOLOAD=${ROWSTOLOAD:--100}

Thanks,
Gangadhar
# 2  
Old 04-11-2011
This can be divided into 2 parts

Code:
export ROWSTOLOAD=${ROWSTOLOAD:--100}

If "ROWSTOLOAD" is defined then
Code:
export ROWSTOLOAD=${ROWSTOLOAD}

else set it to
Code:
export ROWSTOLOAD=-100

In general if a variable is needed to be exported but you don't know if its already defined then you use the above syntax to define it to a default value in case it is not set.
Suppose you have variable "VAR" and not sure if it already had some value, but you want it to be defaulted to "300" if it's not defined, then you use the command

Code:
export VAR=${VAR:-300}

These 3 Users Gave Thanks to aster007 For This Post:
# 3  
Old 04-11-2011
EDIT: aster007 explains it better!

Does it work ??

From what I know [very little], it shouldn't.

The parenthetical ${text} is a character interpretation, and
The parenthetical $(num) is a numerical interpretation.
This User Gave Thanks to AlphaLexman For This Post:
# 4  
Old 04-11-2011
AlphaLexman is correct - This won't work with numbers.
If "ROWSTOLOAD" is null, then the output in this case will be "{ROWSTOLOAD:--100}" instead of -100
This User Gave Thanks to aster007 For This Post:
# 5  
Old 04-11-2011
This syntax is legal and it should work fine in ksh, bash, or even the old Bourne shell.

Code:
$ ROWSTOLOAD=""
$ export ROWSTOLOAD=${ROWSTOLOAD:--100}
$ env | grep ROWS
ROWSTOLOAD=-100
$


edit ---

Well the ROWSTOLOAD=${ROWSTOLOAD:--1} is valid in the Bourne shell. But I just remembered that the Bourne shell does not allow you to set a value in the export statement like that. But you can use the obscure feature of redefining the environment for a single command by prepending assignment and express it like this:
Code:
ROWSTOLOAD=${ROWSTOLOAD:--1}  export ROWSTOLOAD

And a test...
Code:
$
$ ROWSTOLOAD=""
$ export ROWSTOLOAD
$ env | grep ROWS
ROWSTOLOAD=
$ ROWSTOLOAD=${ROWSTOLOAD:--100}  export ROWSTOLOAD
$ env | grep ROWS
ROWSTOLOAD=-100
$

That was with ksh. This syntax really should be universal.

Last edited by Perderabo; 04-11-2011 at 06:40 PM.. Reason: Correction on Bourne export statement
This User Gave Thanks to Perderabo For This Post:
# 6  
Old 04-12-2011
Thanks everyone for the explanations. It helped and I got it Smilie

Regards,
Gangadhar
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

There's a unknown command on line 1 and i don't know whats causing it.

My OS is Linux GL version 2.4.26. I am trying to make a shell script that outputs a chart displaying info of who is online, boot time, and the real time, I have manage to get it to work, but I still get the error "./user/script: line 1: : command not found." I do in fact have access to root, if... (2 Replies)
Discussion started by: thatguy565
2 Replies

2. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

3. UNIX for Dummies Questions & Answers

How to export a command ?

Hi The command "ssh -V" works as normal user but fails as root. As Normal user: bash-3.00$ ssh -V OpenSSH_5.9p1, OpenSSL 1.0.0e 6 Sep 2011As Root user: # ssh -V bash: ssh: command not found Thanks (1 Reply)
Discussion started by: frintocf
1 Replies

4. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

5. UNIX for Advanced & Expert Users

whats command for search including sub directory ?

What is the command for search the program name from the entire directory (all directories in the unix box, means including sub directories...) (2 Replies)
Discussion started by: gksenthilkumar
2 Replies

6. UNIX for Advanced & Expert Users

Export command

Hi all, Want to know what does export command do?? What is its functionality? And on a shell prompt $at=1 $ echo $at 1 The variable above is it available to other script??? (3 Replies)
Discussion started by: prakash.kudreka
3 Replies

7. Shell Programming and Scripting

Whats wrong with the mv command

I am sorry guys I have figured out the error myself. (0 Replies)
Discussion started by: dsravan
0 Replies

8. Programming

whats the command in unix

what is the command to print the text in a specifed location eg i have text ("i am here"); i have to print it on location 20,20 wat is the command and which header file it uses i am currentlr working in solaris 5.8 using unix (1 Reply)
Discussion started by: ramneek
1 Replies

9. Solaris

Whats the command to see

What fonts are installed on a Solaris 8? I have no GUI so a command line command would be great. Thank you (2 Replies)
Discussion started by: Acleoma
2 Replies

10. Shell Programming and Scripting

Whats the Vhost Command for the Unix Shell

anyone know? would be greatly thankful. (4 Replies)
Discussion started by: shellnewbie
4 Replies
Login or Register to Ask a Question