HomeSoftwareGamesMusicForum

Editing variables (2)

Functions: To distinguish functions from variables, each function name must be preceded by -f, -F or -p. The function doesn't have to exist yet. If necessary, an empty function definition is generated. The options correspond to different modes:

  1. -f name: Pure temporary editing. Usable for generating and testing small functions on the fly, and restricted to bash. Bash can reproduce internally saved functions as text, formatted in a bash-specific way. This format doesn't look very pretty, but it works anyway. All function definitions are put into a single file, together with the variable settings.

    In contrast to bash, ksh can only print the text of a function if the file it has been read from exists. Without the source file, the function may still be called, but no longer reproduced in text form, so using a temporary file doesn't make sense here. Consequently, in the ksh version option -f works the same as -F (see below).

  2. -F name: Editing using a permanent file. This is necessary if you want to change a function in different shell sessions. Instead of putting it in a temporary file, the text is saved in in a file named after the function in a special diretory. The directory's path can be assigned to the variables BASH_VARED_FDIR or KSH_VARED_FDIR, respetively. The defaults are ~/bash-funcs and ~/ksh-funcs. No source file in this directory is deleted automatically, this has to be done by the user. Note that if editing a function defined elsewhere, two versions exist in parallel - the original and the one created by vared. If the original version is loaded during logon, it will be the one that is active, but any following vared call activates the changed one. Thus a function can be edited step by step without touching the original version.
  3. -p name or -p path: Direct editing of a function source. If the parameter is a simple name, the source will be looked up using $FPATH. If it isn't (i.e., it contains at least one '/'), it is considered the path of the source. Here, in contrast to (2), the "official" version of the function is changed, so be careful.
Bash version
Ksh version
up
Created 2011-08-11 by mopcoge