0

Basically, how to make this two step process:

$:/ cd Users
$:/Users ls
user1 user2 user3

A one step process:

$/ cd Users
$:/Users
user1 user2 user3

The pseudo code for the bash script could be :

after changing directories, pause the input state and take another command
command('ls')

edit Here is a great bash reference - http://cb.vu/unixtoolbox.xhtml#scripting

edit-2 http://bhami.com/rosetta.html

edit-3 What are the special dollar sign shell variables?

Community
  • 1
  • 1

1 Answers1

0
alias mycd='cd $(history 1 | sed "s/.*mycd \(.*\)/\1/") && ls #'
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • This doesn't work properly. For `mycd somedir`, it expands to `cd somedir && ls somedir` and complains about `somedir` not existing. Neat idea with the history manipulation, though. – Benjamin W. Nov 08 '15 at 07:18
  • This is the desired behavior when somedir not exists. – Cyrus Nov 08 '15 at 07:54
  • No, I don' think it is: if `somedir` exists, your command does `cd somedir` into it and then issue `ls somedir` instead of just `ls`. DV not from me, btw. – Benjamin W. Nov 08 '15 at 08:25
  • Or you can flip it around: `alias mycd='ls $(history 1 | sed "s/.*mycd \(.*\)/\1/") && cd\'` so you don't have unexpected behaviour by commenting out the rest of the line. – Benjamin W. Nov 08 '15 at 08:33
  • 3
    Seriously, why do you need to fiddle with aliases and history to produce some broken code, while just this is robust (and is portable)? `mycd() { cd "$@" && ls; }`. – gniourf_gniourf Nov 08 '15 at 08:50
  • That works! Very cool...I'll need to locate a bash reference to decode : ) – just another profile name Nov 08 '15 at 18:45