1

This is a terminology/architecture question.

Some of the most basic implementations for easier control of a system are variables and aliases (and some might add symlinks).

Both variables and symlinks "sit on the background" and can be called by the user (I guess "expanded" is good for both).

I ask if variables and aliases fall under the same category because I want to better name a file that contains a list of them (first portion is variables, second portion is aliases that some of them utilizes some variables).

Instead of something general like "background_data.sh" I'd like to give a more "standard" name, something that might resemble a group or category that both might share.

  • Possible duplicate of https://stackoverflow.com/questions/7342735/bash-command-whats-the-difference-between-a-variable-and-an-alias (although on a different Stack Exchange site). – aliceinpalth Feb 03 '18 at 01:17

3 Answers3

3

The "category" that aliases, functions, variables etc. would fall under is environment, as in "shell environment".

Variable and aliases are very different thing though, and so are symbolic links (which are not part of the shell environment, but things in the filesystem, independent of the shell).

  • A variable, whether a shell variable or an environment variable, hold data in the form of strings.

  • An alias is a convenience shortcut for you to use in interactive shell sessions to save on typing often repeated commands. Aliases are expanded at in a separate evaluation stage from variables. Note that in scripts, you will most likely want to use functions rather than aliases as they are more than just simple text substitutions of command names1.

  • A symbolic link is a special type of file in the filesystem that automatically gets resolved to a path when accessed (loosely speaking).

As to what to call your file; it sounds like a file that is supposed to be sourced (either through . in any sh-like shell, or with source in shells that has that command) to set up an environment for some application or process, so I could suggest something like application-name.env or process-name.env, possibly?


1 Aliases in scripts is a bit of a pet peeve with me. Aliases, as I said, are for convenience in interactive shells where one might want to always add the -F flag to ls and therefore define alias ls='ls -F' or something similar. In scripts though, you'd want to be more verbose. There are at least two reasons for this (personal opinions follow):

  1. Saying cp or rm in a script should do exactly that. Standard commands should not be overridden by aliases in scripts, or they will be extremely troublesome to debug.

  2. Aliases are for use on the interactive command line (you type them time and time again, for speed and/or to save your fingers and hands). A script is written once (and possibly improved upon). This allows you to write the script in such a way that it can be easily read and understood by others (or by yourself in a few weeks), which means you can allow yourself to be more verbose when writing a script. The benefit is maintainability.

  3. An alias can not take arguments, at least not in the same way that a function can. This makes functions much more versatile than aliases. Rather than aliasing a command, you make a function that not only calls the utility by verifies that arguments are correct before calling it and that the result comes back as expected, for example. A function could even do its own command line parsing if you so wish, and could that way serve as its own "utility" within the script.

I'm writing some of my scripts in projects where many people are involved, for work, so that's my perspective.

Kusalananda
  • 333,661
0

An aliases is technically a definition used by the command interpreter. Both setting a variable and setting an alias would be a form of assignment.

While you can set, write, unset and delete aliases, they are however semantically distinct from variables in shell as they are global and do something other than store a value.

jdwolf
  • 5,017
  • No, an assignment of a value to a variable is not the same as creating an alias. Creating an alias is not an assignment from the point of view of the shell. – Kusalananda Feb 03 '18 at 10:52
  • The OP is basically asking about the semantic significance of alias vs variable. You don't have to tell me that alias is in fact implemented entirely differently to variables because that ultimately doesn't really matter. Aliases are a thing you can get, set, allocate and delete. – jdwolf Feb 04 '18 at 04:17
0

The difference being explained in the other answers, I think for your purpose the file extension rc would be fitting:

It is used for any file that contains startup information for a command.

It comes in different flavours, as <appname>rc, <appname>.rc or <appname>-rc. Well-known examples are /etc/inputrc, ~/.bashrc and ~/.vimrc.

Murphy
  • 2,649