-1

I would like to write an alias in csh that will call bash and then change dir to a different dir to grab the .profile

For example:

alias setbash 'bash -o vi; cd bashdir; . ./.profile'

That alias statement invokes the bash -o vi but once it has the new shell, it does not execute the rest of the alias.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631

3 Answers3

0

You need to pass the command to run to the bash you are running and not make it a separate parent shell command.

Try bash -o vi -c 'cd bashdir; . ./.profile'.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
0

I don't know of any way to invoke bash and tell it to execute some specified commands and then go into interactive mode. In your case, as you've seen, the bash -o vi command will execute first, and will continue until that shell exits; only then will csh (attempt to) execute the cd and . commands (and since . isn't a csh builtin, it will probably fail).

I'm assuming from your use of -o vi that you want an interactive bash shell, though you didn't actually say so.

bash will execute commands in certain files on startup, depending on whether it's a login shell or not (.profile, .bash_profile, .bashrc, etc.). See the bash documentation for details on which file is executed in which circumstances.

To have bash execute those commands on startup, put them in, for example, $HOME/.bashrc. If you don't want them executed every time bash runs, you can control them with an environment variable.

For example, in csh:

alias setbash 'env USE_BASHDIR=1 bash -o vi'

and in .bashrc:

if [ "$USE_BASHDIR" ] ; then
    cd bashdir
    ./.profile
fi

(You can also do set -o vi in .bashrc rather than passing -o vi on the command line.)

In the long run, though, you'll probably be better off using just bash and abandoning csh. (I used tcsh for many years and I've finally dropped it in favor of bash.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
0

Even in wicked Csh, cmd1; cmd2 will only invoke cmd2 after cmd1 finishes.

I'm guessing you want something like

alias setbash 'bash -o vi --rcfile bashdir/.profile'

If you really require Bash to cd into bashdir you can put that in the rcfile you pass in. (Create a separate file with your original commands if you don't want to change .profile.)

tripleee
  • 175,061
  • 34
  • 275
  • 318