Sponsored Content
Operating Systems OS X (Apple) Don't understand the practical difference between command aliases and environmental variables Post 302964067 by Don Cragun on Saturday 9th of January 2016 04:11:06 PM
Old 01-09-2016
When you are typing commands into a shell (such as bash), the shell expands aliases that you have defined (such as ll in your example). Those aliases are not expanded when your shell is executing commands contained in a file (i.e., a shell script).

Some utilities look at variables defined in their environment and if specific variables are found, those utilities behave differently. The environment variable affects they way those utility behave no matter how that utility was invoked (both by typing the utility name into the shell and by finding a request to run it from a shell script). When export LESS=-N is in the environment of your shell on OS X and you invoke the less utility, the output produced by less will include line numbers in the output.

For example, if you type in the commands:
Code:
unset LESS
man less|less

you will see the man page for the less utility. But, if you type in the command:
Code:
export LESS="-N"

and later type in the command:
Code:
man less|less

you will see the man page for the less utility with each line preceded by its line number.

I personally believe that the LESS environment variable (and similar environment variables designed to alter the behavior of a commonly used utilities) is dangerous because some shell scripts depend on normal less output and if they invoke less not knowing that LESS has been set, the output they see may be misinterpreted.

But there are some environment variables that are expected to be set to get proper operation from lots of utilities. These include, but are not limited to:
  • HOME which defines your home directory,
  • LANG and the LC_ALL, LC_COLLATE, LC_NUMERIC, .... which specify the codeset that is to be used when reading and writing files and what language and locale-specific customs should be used when looking at dates, times, numbers, sorting characters, etc.,
  • PATH which defines the directories your shell should search when trying to find commands,
  • TERM which tells utilities formatting output for your terminal lots of things about the capabilities of the terminal (or terminal emulator) you are using,
  • USER which defines the name of the user who logged into the current terminal session,
  • etc.
Run the env command to see what is currently set in your environment.

Note that if PAGER is set to less in your environment and you have set LESS in your environment to -N, the output from the man command will include line numbers (and it may make reading the man pages harder since they were formatted assuming that line numbers would not be included when they were displayed). Note that environment variable names (and utility names and option names and most other strings used in shell commands and scripts are case sensitive).
These 3 Users Gave Thanks to Don Cragun For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

i don't understand the "sort" command

i have been trying to understand this chapter titled "Searching for Files and Text" for a few weeks now. unfortunately, this chapter is one of those things, that no matter how hard you try and how long you try for, you are incapable of understanding (at least in my case) this entire chapter,... (2 Replies)
Discussion started by: xyyz
2 Replies

2. UNIX for Advanced & Expert Users

Environmental Variables - where stored ?

Hi all ! Yesterday I defined an environmental variable PATH, but today when I restarted machine, I could not see that it was stored any place. Is there any file where I could save the settings ? I have quite a few env.variables defined, so I need a smarter way to define. regards D (5 Replies)
Discussion started by: DGoubine
5 Replies

3. Shell Programming and Scripting

don't understand a command "."

Hi all, I have a script with those two lines : test -f $PWD/mysetup.txt . $PWD/mysetup.txt I understand the first one, but could anyone explain me the role of the second one? All the thing I find is the usage : Thx in advance (3 Replies)
Discussion started by: Moumou
3 Replies

4. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

5. AIX

Best way to setup my own environmental variables ?

I am writing a few korn scripts to be used by all our operators on several 4.1/4.2 AIX servers. I want to create environmental variables that once set, can be read/modified by my scripts (ex: specific folders, file names, conventions, general values, ...). I thought this would be better then... (4 Replies)
Discussion started by: Browser_ice
4 Replies

6. Homework & Coursework Questions

I don't understand some basics..

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1)find all lines in file ,myf that contain all the words cat dog and mouse in any order and start with the letter... (1 Reply)
Discussion started by: cudders
1 Replies

7. UNIX for Dummies Questions & Answers

Another Simple BASH command I don't understand. Help?

I have a text file called file1 which contains the text: "ls -l" When I enter this command: bash < file1 > file1 file1 gets erased. However if I enter this command: bash < file1 > newfile the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get... (3 Replies)
Discussion started by: phunkypants
3 Replies

8. UNIX for Dummies Questions & Answers

I don't understand conditions :(

Hi there, I have a very general question. I'm rather new to (bash) shell scripting and I don't understand how conditions work... I've read numerous tutorials but I don't get it. I really don't. Sometime what I do works, sometime it doesn't and that's frustating. So what's the actual difference... (0 Replies)
Discussion started by: hypsis
0 Replies
All times are GMT -4. The time now is 07:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy