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 }