Sponsored Content
Top Forums Shell Programming and Scripting Command substitution inside of a variable expression (AIX, KORN) Post 302761151 by sydox on Friday 25th of January 2013 08:24:21 AM
Old 01-25-2013
Command substitution inside of a variable expression (AIX, KORN)

Hello all. This is my first post/question on this site.
I’m a new Systems Analyst with previous experience with BASH. Although now I'm using AIX, and I’m trying to get a feel for the Korn shell (for those of you that don’t know AIX only uses the KORN shell).
I hope I put this into the correct forum topic; if not I apologize!

I am trying to use a command substitution inside of a variable expression:

Code:
#!/usr/bin/ksh

Code:
cd ${1:-`pwd`}; pwd; ls -l

I want it to cd to a directory that is provided as an argument, if no directory is provided then i want cd to default to the current directory. Then: pwd; ls -l

It’s pretty straight forward. This works if a directory is provided; where I'm getting caught is that if no argument is provided cd goes to the home directory, as if :- didn't default to `pwd`. I have also tried:

Code:
cd ${1:-.}; pwd; ls -l



The pwd and ls –l part of the code works with no problem. Also to note: I was talking to a co-worker and they commented that due to working under AIX that perhaps it doesn’t support variable expressions. If that is the case then fine, now I know!

Thanks in advance for your help.

-SIdney
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

2. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

3. Shell Programming and Scripting

How to use variable with command substitution in variable

For example I have variable like below echo $OUTPUT /some/path/`uname -n` when I try to use the variable OUTPUT like below cd $OUTPUT or cd ${OUTPUT} I am getting bad substituion error message $ cd $OUTPUT ksh: cd: bad substitution $ cd ${OUTPUT} ksh: cd: bad substitution ... (1 Reply)
Discussion started by: rajukv
1 Replies

4. Shell Programming and Scripting

How to use same variable value inside as well as outside of the awk command?

Hi Jim, The following script is in working state. But i m having one more problem with awk cmd. Could you tell me how to use any variable inside awk or how to take any variable value outside awk. My problem is i want to maintain one property file in which i am declaring variable value into that... (12 Replies)
Discussion started by: Ganesh Khandare
12 Replies

5. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

6. Shell Programming and Scripting

[Solved] Command Substitution and Variable Expansion within a Case

Hello All, I don't write scripts very often, and in this case I am stumped, although it may be a bug in the version of bash I have to use (it's not my system). I want to extract a specific string snippet from a block of text (coming from a log file) that is dependent on a bunch of other... (1 Reply)
Discussion started by: jaimielives
1 Replies

7. UNIX for Dummies Questions & Answers

Variable inside command substitution

Hello people. Part of my script: SUBSETID=`echo $PMFILE |sed 's/pmresult_//' | sed 's/_*//'` MAPFILE=`find /huawei/cell /huawei/nodeb /huawei/rnc -name 'mapping_$SUBSETID.txt' |grep -v backup` Unfortunatelly variable $SUBSETID in the MAPFILE declaration will not return the... (3 Replies)
Discussion started by: drbiloukos
3 Replies

8. UNIX for Dummies Questions & Answers

[solved]Korn, disabling * substitution

If I execute the following line of code: echo "*" I get a list of files in the current directory. What if all I wanted to do was display the asterisk itself? What does the code have to look like so all I get is an asterisk? Thanks ahead of time for your assistance ----------... (3 Replies)
Discussion started by: Wreckoning
3 Replies

9. Shell Programming and Scripting

Store command inside variable

Is it possible to store a command inside a variable? i want this piece to be stored inside a variable, so i can use it later in a different command $u | cut -d " " -f 2 var="$u | cut -d " " -f 2" eval $var I tried to use eval but I receive this error: -f 2: command not found ... (5 Replies)
Discussion started by: velos
5 Replies

10. Shell Programming and Scripting

String variable as part of expression in find command

Hi, I am new in scripting, and I am currently working on a script that will look for other files in a certain directory and exclude some file type. this works fine:Find_File2Exclude=`find ${paths} -maxdepth 1 -type f \( ! -iname '*.out' ! -iname '*.auc' ! -iname '*.cps' ! -iname '*.log' ! -iname... (4 Replies)
Discussion started by: kedd05
4 Replies
XTERMCONTROL(1) 						   User Commands						   XTERMCONTROL(1)

NAME
xtermcontrol - dynamic control of XFree86 xterm properties. SYNOPSIS
xtermcontrol [OPTIONS]... DESCRIPTION
xtermcontrol makes it easy to change colors, title, font and geometry of a running XFree86 xterm(1), as well as to report the current set- tings of the aforementioned properties. Window manipulations de-/iconify, raise/lower, maximize/restore and reset are also supported. To complete the feature set; xtermcontrol lets advanced users issue any xterm control sequence of their choosing. OPTIONS
--fg=COLOR Set foreground color (see also COLOR NAMES). --bg=COLOR Set background color. --colorN=COLOR Set N'th [0-15] color. --highlight=COLOR Set highlight color. --cursor=COLOR Set cursor color. --mouse-fg=COLOR Set mouse pointer foreground color. --mouse-bg=COLOR Set mouse pointer background color. --font=FONT Set font name (see also FONT NAMES). Alternatively it is possible to specify a fontmenu index as '#[0-6]' or navigate the fontmenu by relative sizes as '#+N' or '#-N', where N is an optional integer. --title=STRING Set window title. Note that mechanisms like the bash(1) PROMPT_COMMAND may overwrite the title. --geometry=WIDTHxHEIGHT+XOFF+YOFF Set size and/or position. Through its control sequences the xterm only recognize positive XOFF and YOFF offsets, which are pixels relative to the upper left hand corner of the display. xtermcontrol is therefore unable to handle negative offsets as described in the X(7x) GEOMETRY SPECIFICATIONS and therefore truncates negative values to zero. --get-fg Report foreground color. --get-bg Report background color. --get-colorN Report N'th [0-15] color. --get-highlight Report highlight color. --get-cursor Report cursor color. --get-mouse-fg Report mouse pointer foreground color. --get-mouse-bg Report mouse pointer background color. --get-font Report font. --get-title Report window title. --get-geometry Report size and position. The size of the text area is reported in characters and the position is reported in pixels relative to the upper left hand corner of the display. --maximize Maximize window. --restore Restore maximized window. --iconify Iconify window. --de-iconify De-iconify window. --raise Raise window. --lower Lower window. --reset Full reset. --raw=CTLSEQS Issue raw control sequence (see also XTERM CONTROL SEQUENCES). --file=FILE Force xtermcontrol to read configurations (see also CONFIGURATION) from FILE instead of the standard personal initialization file ~/.xtermcontrol. --force, -f Skip TERM environment variable check. --verbose, -v Print verbose reports. --help, -h Print help message and exit. --version Print the version number and exit. CONFIGURATION
xtermcontrol reads a default, ~/.xtermcontrol, or a user specified configuration file on startup. Each line in the file is either a com- ment or contains an attribute. Attributes consist of a keyword and an associated value: keyword = value # comment The valid keyword/value combinations are: foreground="COLOR" background="COLOR" highlight="COLOR" cursor="COLOR" mouse-foreground="COLOR" mouse-background="COLOR" geometry="WIDTHxHEIGHT+XOFF+YOFF" font="FONT" color0="COLOR" color1="COLOR" color2="COLOR" color3="COLOR" color4="COLOR" color5="COLOR" color6="COLOR" color7="COLOR" color8="COLOR" color9="COLOR" color10="COLOR" color11="COLOR" color12="COLOR" color13="COLOR" color14="COLOR" color15="COLOR" Whitespace is ignored in attributes unless within a quoted value. The character '#' is taken to begin a comment. Each '#' and all remaining characters on that line is ignored. FONT NAMES
xtermcontrol accepts any X(7x) FONT NAMES. Font names like '-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1' are very cumber- some to write, so it is convenient to make use of aliases, e.g. 'fixed' or '8x13', if present in fonts.alias files of the font directo- ries. COLOR NAMES
xtermcontrol accepts any X(7x) COLOR NAMES. Basically this means that colors are specified by name or rgb value, e.g. 'blue', 'rgb:0000/0000/FFFF' or '#00F'. Colors are typically reported by the xterm in a device-dependent numerical form, e.g. 'rgb:0000/0000/FFFF'. Note that old syntax rgb values should always be quoted to avoid '#' being interpreted as the beginning of a comment by the shell (see also FILES). XTERM CONTROL SEQUENCES
The secret behind xtermcontrol is xterm control sequences. All the possible (there are a plethora of them) control sequences are documented in ctlseqs.txt, found in the xterm(1) distribution (see also FILES). TROUBLESHOOTING
If read/write permissions on the tty's are changed so that special group membership is required to be able to write to the pseudo terminal, the easiest workaround is to install xtermcontrol setuid root. Xterm(1) has three resources, allowWindowOps, allowTitleOps, and allowFontOps, that enables or disables special operations which xtermcon- trol relies on. If any of these resources are set (or defaults) to 'false' xtermcontrol may hang. The resources corresponds to xtermcon- trol options as: allowWindowOps: --raise --lower --restore --maximize --iconify --de-iconify --get-title --geometry --get-geometry allowTitleOps: --title allowFontOps: --font --get-font All three resources can usually be enabled for the current xterm session via a menu; ctrl+rightclick and look for menu item names like 'Allow Window Ops'. To set these resource values persistently you can add the following to either your local ~/.Xdefaults file, or to a system-wide resource file like /etc/X11/app-defaults/XTerm: *VT100.allowWindowOps: true *VT100.allowTitleOps: true *VT100.allowFontOps: true FILES
<XRoot>/X11/rgb.txt Default rgb color name file location. ctlseqs.txt Xterm control sequences documentation. Distributed with xterm from http://dickey.his.com/xterm/ SEE ALSO
xterm(1), X(7x) COPYRIGHT
Copyright (C) 2002-2009 Jess Thrysoee <jess@thrysoee.dk> xtermcontrol 2.10 October 17, 2009 XTERMCONTROL(1)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy