Command expansion and variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command expansion and variables
# 8  
Old 06-14-2013
Quote:
Originally Posted by BrandonD
I am new to unix, so I kind of understand, but I just assumed that putting a simple command like date or ls, in a variable, it would output the same as the original command.
The behavior that you expect can be achieved using alias command:
Code:
$ alias d="date"
$ d
Fri Jun 14 13:27:23 PDT 2013

Check the man page for further reference:
Code:
man alias

# 9  
Old 06-14-2013
You can put quoted command expansions in $PS1 so your prompt has the current time or such, so the shell does an eval at each prompt. Some things are in variables already, so never $( pwd ) just $PWD. Type 'set|more' and see all your variables.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. UNIX for Dummies Questions & Answers

Using find command with variables

I have a number of files in the /tmp directory with PET-DOG in their name. I want to delete them, leaving only files with PET-CAT and PET-HORSE. I'd like to use the find command to locate those files (by using a variable) and then I'd like to delete them. However, I can't find a way to do this. I... (3 Replies)
Discussion started by: newbie2010
3 Replies

3. Shell Programming and Scripting

Need help with paste command using variables

How can I accomplish this? I basically want to merge two variables onto the same line. I can do it with two FILES this way: $ cat /tmp/users_in.list | awk -F "," '{print $2}' | cut -c -1 > first.initial $ awk -F "," '{print $1}' /tmp/users_in.list | awk '{print $1}' > last.name $ paste... (5 Replies)
Discussion started by: greenlightening
5 Replies

4. Shell Programming and Scripting

Variables in an awk command

I am scripting a process where usernames are added to the end of a specific line in a file. using this: awk 'NR==1{$NF=$NF" TEXT"}1' myfileworks, and then I would use > tempfile && mv tempfile myfile HOWEVER. Being that this is to be scripted, I am trying to do something like: awk:... (8 Replies)
Discussion started by: magicjoe
8 Replies

5. 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

6. Shell Programming and Scripting

Variables in SED command

Hi all, I want write a script to display 5rows at times from a input file. my out like: echo " display started" r1 r2 r3 r4 r5 ... Some action items... again i need next 5 lines. can you please advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Get command with variables

I'm writing a script to get a datestamped file from a ftp server. It seems that the "get" command does not respect variables. Anyone knows how to fix the problem? I'm trying to get a file named "rcsnotesYYYYMMDD" Here's my script today=`date +%Y%m%d` tput clear user <login> <password>... (1 Reply)
Discussion started by: mliu3
1 Replies

9. Shell Programming and Scripting

Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||'

Hi , could anyone help me out with this problem. sample.txt has this content : u001- this is used for project1 || u002- this is used for p2|| not to be printed u003- this is used for project3 || u004- this is used for p4 || u005- this is used for project5 || u006- this is used for p6... (9 Replies)
Discussion started by: Balaji PK
9 Replies

10. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question