ls command >> Syntax Error.

Hi all,
I'm experiencing some problems with ls command. after typing ls in MatlabR2013a, I get the contents, but this is preceded by: >> ls set: Syntax Error.
Though everything is displayed well, I find it quite annoying. Any ideas what may cause this?
OS: Mac OSX 10.7.5
terminal usage doesn't give this error. location ls: /bin/ls
Best, Cédric

5 commentaires

the cyclist
the cyclist le 20 Août 2013
I'm not sure I understand what you mean by "terminal usage doesn't give this error". Do you mean that you get the error if you call ls from a function, but not the command window? Or do you mean something else?
Walter Roberson
Walter Roberson le 20 Août 2013
Please check
which -all ls
ckoolschijn
ckoolschijn le 21 Août 2013
with "terminal usage" I meant when I call the ls command from terminal window, so outside the matlab environment.
which -all ls returns: /Applications/MATLAB_R2013a.app/toolbox/matlab/general/ls.m
so this is indeed a different path to the ls function compared to terminal
Laurent
Laurent le 21 Août 2013
The matlab function ls.m should call the unix 'ls' command on Mac OS X. Just as a test, what happens when you type for example 'ls -a' in Matlab? Does that work?
JYOTI CHAHAL
JYOTI CHAHAL le 21 Avr 2022
after typing ls -a the output is "-a not found"

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 21 Août 2013

0 votes

Check your ~/.bashrc /etc/profile ~/.bash_profile ~/.bash_login and ~/.profile and also any file named by the shell environment variable ENV .
A common error in shell initialization scripts is to use something similar to
set $((tset))
or
stty `tset -q`
(except there would be some option flags involved) to try to set the "terminal type". The "terminal type" is not defined except for interactive login shells. People tend to construct the above initialization files as if they are being executed in that context, but the assumption is not always true. Anything in the shell initialization that depends upon it being an interactive login shell, should be protected with a specific test that a terminal is really available. In the sh / ksh / bash family that can be done with
if -t 0
such as
if -t 0
stty `tset -q`
fi

5 commentaires

ckoolschijn
ckoolschijn le 21 Août 2013
I'm not sure I understand your solution. I don't have statements as you describe above in any of the suggested profile-files.
Walter Roberson
Walter Roberson le 21 Août 2013
Is there anywhere in those initialization files in which you have a "set" command that involves an environment variable that is assumed to exist?
When you use MATLAB's ls(), it uses system(), which in turn creates a shell process and executes the given command within the shell process. The shell process might be executing an initialization script (e.g., to define system-level environment variables.) If the initialization script goes wrong you can end up with "set: Syntax Error." from the shell (rather than from MATLAB.)
What happens if you use
!ls
?
ckoolschijn
ckoolschijn le 27 Août 2013
Modifié(e) : Walter Roberson le 27 Août 2013
I had two set comments:
set autolist
set filesc
If I comment these out, I still get the same message. The same happens with !ls.
You state that matlab should use system ls, yet here it uses its own: ls.m
Walter Roberson
Walter Roberson le 27 Août 2013
Modifié(e) : Walter Roberson le 27 Août 2013
Read the source for ls.m . You will see that on unix systems it does a unix() call to use the system's ls.
Question: have you set up a shell 'alias' for ls ? e.g.,
alias ls 'ls -C'
?
ckoolschijn
ckoolschijn le 28 Août 2013
You're right, it does call the unix() ls.
no aliases are set in my .bash files of .alias. However, I solved the problem, there as I previously also used tcsh shells, there was also a .tcsh file in which some set variables were defined (yet no ls), after moving it to .tcsh.bak, the syntax error is gone. Many thanks for your help! Cheers

Connectez-vous pour commenter.

Catégories

En savoir plus sur Entering Commands dans Centre d'aide et File Exchange

Tags

Question posée :

le 20 Août 2013

Commenté :

le 21 Avr 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by