0
Pretty new to bash scripting. Trying to over ride the ls -la command to be: ls -la | more
(Seems more useful for me).
I added this to the end of my .bashrc
.
154 # alias 'ls -la'='ls -la | more'
155 # this did not work because aliases
156 # are not allowed to have spaces in
157 # them. => have to make function:
158 ls() {
159 if [[ $@ == "-la" ]];
160 then
161 echo "test";
162 command ls -la | more;
163 else
164 command ls "$@";
165 fi;
166 }
But I get this error when I open a new terminal:
bash: /users/me/.bashrc: line 158: syntax error near unexpected token `('
bash: /users/me/.bashrc: line 158: `ls() {'
When I add function
before ls() {
there are no complaints but there is no change to ls behavior. Thanks.
Update
Trying to narrow down the issue I did this:
159 ls() {
160 #if [[ $@ == "-la" ]];
161 # then
162 echo "test"
163 # command ls -la | grep vim;
164 #else
165 # command ls "$@";
166 #fi;
167 }
but I still get the same error. I think that the main problem may be that it is in the bashrc file?
Update
Strangely this works
159 function ls() {
160 #if [[ $@ == "-la" ]];
161 # then
162 echo "test"
163 # command ls -la | grep vim;
164 #else
165 # command ls "$@";
166 #fi;
167 }
Running solaris 10 with the same bash as you. My assumption was that it was just a mistake with the spaces or something like that. Or maybe brackets. Did you do a direct copy-paste of my code? And it worked? Thanks for the help! – sixtyfootersdude – 2010-02-08T16:53:55.677
1Yes, I copied and pasted it exactly into my .bashrc, removed line numbers, and no error was reported. – njd – 2010-02-08T17:28:58.650
very strange.. No idea what the error suggests? – sixtyfootersdude – 2010-02-08T17:36:22.577
Ok that is mostly working now. Did the if statement ever evaluate to true for you? Ie: did
ls -la | more
ever execute? – sixtyfootersdude – 2010-02-08T17:50:03.810HA! I have an alias that takes ls and maps it to ls -F and that was messing things up. Problem solved. – sixtyfootersdude – 2010-02-08T18:03:55.070
D'oh! The simplest solutions are always the best. Nice to know you got it fixed in the end. – njd – 2010-02-08T18:54:45.737