ksh: what does var=$(command) mean?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh: what does var=$(command) mean?
# 1  
Old 10-26-2010
ksh: what does var=$(command) mean?

hi,

i can see in a script

it contains

Code:
var=$(
         myFile | grep -i err
)

why has this person done it like this? why not just

Code:
var=`myFile | grep -i err`

thanks
# 2  
Old 10-26-2010
Well, '`' is small (hard to see/discern from "'"), vi '%' does not pair them, and it
does not nest. I am not sure if it swallows linefeeds -- probably. So, good style is to use ksh and $(). Also, use closed paren pairs in 'case' so they stay in balance for vi '%'.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 10-26-2010
backtick `` means pass the result as a variable in old fashion
Using $() is new fashion (some shell implementation may not support this way to write things
This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 10-26-2010
thanks guys
# 5  
Old 10-26-2010
Yes, $() is not supported in bourne shell (sh).
# 6  
Old 10-26-2010
Solaris' /bin/sh is one shell in a current OS that keeps popping up that does not support $() . But you can use /usr/xpg4/bin/sh instead ...
# 7  
Old 10-26-2010
Note that, at least as far as ksh93 is concerned, there is a subtle difference between command substitution using $(...) and command substitution using `...`. In the second (obsolute) form, the string between the quotes is processed for special quoting characters before the command is substituted.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk command to output in var

Hi I have this command, which counts number of lines in a specific file and then prints it on screen.nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename I would like to have the output put into a variable, but can't seem to find the correct argument for it. How do I... (3 Replies)
Discussion started by: bulleteyedk
3 Replies

2. Shell Programming and Scripting

Csh , how to set var value into new var, in short string concatenation

i try to find way to make string concatenation in csh ( sorry this is what i have ) so i found out i can't do : set string_buff = "" foreach line("`cat $source_dir/$f`") $string_buff = string_buff $line end how can i do string concatenation? (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

ksh - building a var

This works #!/bin/ksh FILE="file.txt" dosumtin () { date >> FILE } for i in {1..5} do dosumtin done cat $FILE But instead of building a file, I want to do the same with a var or an array. That is, to build one that saves all 5 of the subs execution responses in a var or an... (8 Replies)
Discussion started by: popeye
8 Replies

4. Solaris

Difference between /var/log/syslog and /var/adm/messages

Hi, Is the contents in /var/log/syslog and /var/adm/messages are same?? Regards (3 Replies)
Discussion started by: vks47
3 Replies

5. Shell Programming and Scripting

${!var} does not work in ksh

Anyone knows why the following function does not work in ksh (it does in bash)? var() # Displays var value; case insensitive { _var="$1" if ; then echo ${!_var} else _var=$(echo "$_var" | tr 'a-z' 'A-Z') echo ${!_var} fi unset _var }$ var home ksh:... (4 Replies)
Discussion started by: victorbrca
4 Replies

6. Shell Programming and Scripting

Problem running var (with spaces) as command

I seem to be fighting bash's shell expansions.. I set this variable: CMD="export MVAR=\"1 2 3\"" if I try to run it, it is clear the shell is parsing along the spaces of the contents of MYVAR: > $CMD + export 'MYVAR="1' 2 '3"' + MYVAR='"1' -bash: export: `2': not a valid identifier... (3 Replies)
Discussion started by: bbw
3 Replies

7. Shell Programming and Scripting

How to use shell var for pattern string at KSH

Hi there, In the following test, how to use shell var for pattern, regular expression. I need to accept pattern at argument, use it to pattern matching at shell script. Test: #!/bin/ksh # name t.sh exp="a@(a|b)" touch aa ab ac echo "\nTest without variable" echo "---------------------"... (2 Replies)
Discussion started by: tkang007
2 Replies

8. Shell Programming and Scripting

Use loop var i within Cut Command

Hi, In the following bash code rather than cutting at a predefined character I would like to cut at position i (i var from loop). Is this possible? I have tried eval, but either it's not possible or my syntax is wrong. thanks Nick for i in {1..9} do theChar=$(echo... (3 Replies)
Discussion started by: de_la_espada
3 Replies

9. Shell Programming and Scripting

Store command in a Var problem

Hi! I strated to script since 1 month and I don't have much expirience but this thing here is strange I have a script where I want to store a svn command in a var to check it later so it's like this #!/bin/sh list=`ssh itadmin@192.168.1.200 "ls /home/svn"` # this stores the list of... (13 Replies)
Discussion started by: ruben.rodrigues
13 Replies

10. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies
Login or Register to Ask a Question