symbolic links, aliases, cls clear
Floyd L. Davidson
floyd at apaflo.com
Wed Apr 12 09:17:36 EDT 2006
"mp" <mailpitches at email.com> wrote:
>i have a python program which attempts to call 'cls' but fails:
>
>sh: line 1: cls: command not found
Hmmmmm... (I don't program in Python, so precisely what is
happening isn't something I'm sure about).
But, note how that line starts with "sh:"! That indicates it is
/bin/sh which is reporting an inability to find a "cls"
command. It suggests that Python (like most other programming
languages) calls shell scripts using /bin/sh as the default
shell.
The problem is that unix has no command named "cls".
>i tried creating an alias from cls to clear in .profile, .cshrc, and
>/etc/profile, but none of these options seem to work.
In /etc/profile and ~/.profile you will cause an alias to be
defined *for* *interactive* *login* *shells*. But not for
non-interactive non-login shells, which is what you are invoking
with Python. The reason is because aliases are not inherited by
sub-shells, and only interactive login shells read those two
files.
Hence your alias is never defined in the subshell your program
executes.
>my conclusion is that a python program that is executing does not use
>the shell (because it does not recognize shell aliases). is this
>correct?
No.
>should i use a symbolic link? if so, where should i place it?
No.
>what is the difference between aliases and symbolic links?
Aliases are a mechanism used by a shell to define a command name
that executes a series of commands. A symbolic link is a
directory entry that de-references another directory entry, so
that either entry points to the same actual file.
>if i execute a command like 'clear' to clear the screen, where does the
>shell look to find the command 'clear'?
It looks in locations specified by the PATH variable. By
default that will be a minimal list defined by the login
program, but it might be significantly added to in the
/etc/profile or other shell init scripts.
The question you need to answer first is what happens if your
Python program tries to execute /clear/ rather than /cls/. If
that works, then your PATH variable is set correctly. If it
doesn't work, verify that there is in fact a program named
/clear/ that can be run from a shell command line. Then figure
out how to set an appropriate PATH variable for your Python
program.
Note that if /clear/ does work, but you want this script to use
/cls/ so that it is portable to some silly OS where a /cls/
exists... You can define a shell function (which will be
inherited by sub-shells) to look like this,
function cls () {
clear;
}
And place it where ever is appropriate (/etc/profile is one place).
>i'm using os x.
I don't know anything about it... :-)
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd at apaflo.com
More information about the Python-list
mailing list