Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > command line alias problem

command line alias problem
Thread Tools
altoid
Fresh-Faced Recruit
Join Date: Nov 2000
Location: Brooklyn
Status: Offline
Reply With Quote
Mar 26, 2001, 07:02 PM
 
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?
     
Eugene
Senior User
Join Date: Nov 2000
Location: Berkeley, CA
Status: Offline
Reply With Quote
Mar 26, 2001, 07:27 PM
 
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
Guest
Status:
Reply With Quote
Mar 26, 2001, 10:16 PM
 
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.
     
altoid  (op)
Fresh-Faced Recruit
Join Date: Nov 2000
Location: Brooklyn
Status: Offline
Reply With Quote
Mar 28, 2001, 09:57 PM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:25 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,