Solved Need help with csh alias

I've made a bash function, but I can't seem to find a way to convert it to make it work in a csh shell.

What I want to do is alias pkg upgrade to pkg upgrade -r Synth.

Any ideas?
Code:
sudo() {
  if [[ $@ == "pkg upgrade" ]]; then
      command sudo pkg upgrade -r Synth
  fi
}
 
Maybe you could slip it in the alias section of the users .cshrc

Code:
# $FreeBSD: releng/11.0/etc/coot/dot.cshrc 278616 2015-02-12 05:35:00Z cperciva
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#

alias h         history 25
alias j         jobs -l
alias la        ls -aF
alias lf        ls -FA
alias ll        ls -lAF
 
Yes, but this issue is "alias" only allow one word (with no spaces). I want to alias multiple words "pkg upgrade" -to- "pkg upgrade -r Synth".
 
That's not the issue - aliases can only contain single word names.

It does not allow "alias pkg upgrade pkg upgrade -r Synth" - as "upgrade" in the alias name is ignored. I am looking for a workaround on this issue.
 
Well I tried a few varaitions with no luck so I broke out a book.
Under alias:
"In a POSIX shell, they can only take arguments after the command"

So i guess a function is indeed needed.
 
why not make a script that detects when pkg gets called with upgrade option, and in this case rewrites the arguments before passing control to pkg itself?
This would be not dependent on the shell being used.
 
Not sure if this is going to work but pkg(8) itself can also have aliases, see /usr/local/etc/pkg.conf. You could create something like pkg supgrade:
Code:
ALIAS
  supgrade: upgrade -r Synth
I've used supgrade as I'm not sure what the effect would be if you overruled upgrade (you might end up with a circular alias looping forever).
 
That's not the issue - aliases can only contain single word names.

It does not allow "alias pkg upgrade pkg upgrade -r Synth" - as "upgrade" in the alias name is ignored. I am looking for a workaround on this issue.
Did you tried something like: alias "pkg upgrade" "pkg upgrade -r Synth"?
 
Back
Top