|
|
command line alias problem
|
|
|
|
Fresh-Faced Recruit
Join Date: Nov 2000
Location: Brooklyn
Status:
Offline
|
|
So I decided to create the file called aliases.mine in ~/Library/init/tcsh/ so I could make up my own command aliases to use while in tcsh. Simple aliases have been working (like alias ls 'ls -la', but when I put the following line:
alias mydf 'df |grep "disk" | awk 'BEGIN {FS=" "} {print $2/2048"GB "$3/2048"GB "$4/2048"GB "$5" "$6}''
into the alias file, when I exit and re-logon, I get:
Missing }.
[localhost:~] username%
as the first 2 lines of the new shell window. I've tried a varation on where I put the single quotes (the last quote on the alias line above is actually two single quotes, not one double quote) and messing around with it and I can't seem to get it to run. But If I run that line in the shell at the prompt it runs fine (obviously w/out the single quotes at start and end)...
Any ideas on this?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2000
Location: Berkeley, CA
Status:
Offline
|
|
Perhaps you can break up that one aliased command into multiple aliased commands. All that punctuation seems to be confusing the shell.
Normally, I restrict aliases to my .tschrc file, but I guess most of you guys will be using your machines as a single-use OS.
|
|
|
|
|
|
|
|
|
xyzplugh
|
|
alias mydf 'df |grep "disk" | awk 'BEGIN {FS=" "} {print $2/2048"GB "$3/2048"GB "$4/2048"GB "$5" "$6}''
The shell doesn't understand that you are trying to "nest" your single quotes. It sees the quote before "df" and after "awk " as a matching pair and everything from BEGIN... on is junk and flags it.
It works interactively because you are not putting on the extra single quotes. Try breaking the awk command into a different alias.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Nov 2000
Location: Brooklyn
Status:
Offline
|
|
That's a good thought I think to break up the one line into 2 aliases. The problem seems to be that the shell will not deal with any nested quotes at all in aliases. I tried changing from single to double just too see if the shell would react differently but no go.
So I just put:
awk 'BEGIN {print "Total Used Avail %age Disk"}'
df |grep "disk" | awk 'BEGIN {FS=" "} {print$2/2097152"GB "$3/2097152"GB
"$4/2097152"GB " $5" "$6}'
into a text file and called the file from an alias.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|