"script" doesn't seem to fully recognize one's environment
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
"script" doesn't seem to fully recognize one's environment
I'm working on a project that, sadly, involves software that seems to have been written by people who love typing long commands (and don't mind correcting the inevitable typos). As a result, some of us have created aliases to reduce the maddening amount of typing that's necessary to execute commands.
Now... as part of a request to "show me how to do this" I tried running a series of these long commands via their aliases and log the session using "script". Oops! "script" doesn't know about all of my environment. Well, by "my environment" I mean the normal collection of shell variables as well as the aliases. That seems to be too expansive of a definition as "script" is unaware that aliases have been defined. I've been using that utility for years (starting on big iron Unixen) and never noticed this before.
Is this normal "script" behavior? -- I see no switches that might help me out.
Is there a workaround? -- The only one that comes to mind is to bite the bullet and write a short shell script that uses the long version of the commands and run that during the "script" session. One other possibility is to source my ".profile" when first logging the session. (Works but sort of a pain.)
Mostly curious if anyone else has run into this and whether there's a clever fix.
No, this is not normal. script inherits your environment including aliases (unless script itself was aliased to something else). Just tested with script from util-linux 2.23.2 (CentOS 7), 2.32.1 (CentOS 8), and 2.34 (Ubuntu 20.04 LTS).
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Original Poster
Rep:
Quote:
Originally Posted by shruggy
No, this is not normal. script inherits your environment including aliases (unless script itself was aliased to something else).
Interesting. I'm running CentOS 8 via Oracle's VirtualBox and script is from util-linux 2.32.1. I'll have to look a tad deeper to see what's going on. May be time for strace though I'm unsure if I'd be able to interpret the results without having the script source code handy.
You know, aliases are lost. So the mentioned shopt was not set. Actually I (we) don't know the real execution environment, therefore we could only guess, but I don't want to.
From the other hand better to use functions instead of aliases, that is more convenient (and should be exported too).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.