i changed the directory using cd $HOME but i dont see any .profile files under that directory. am i missing it? or it can be under some other directory? is it required to have it?

Dani AI

Generated

Good question, . Building on ’s point that startup files depend on the shell: in ksh, a per-user .profile is optional, and dotfiles are hidden by default. First, check if it’s actually missing.

test -f "$HOME/.profile" && echo ".profile exists" || echo "no per-user .profile"

If it’s missing, that’s fine. Create a minimal one and, for ksh specifically, point ENV at a separate interactive rc file (commonly ~/.kshrc). Put aliases and interactive tweaks in ~/.kshrc, not in .profile.

# Create a basic ~/.profile
printf 'umask 022\nexport ENV="$HOME/.kshrc"\n' > "$HOME/.profile"

# Create a basic ~/.kshrc for interactive ksh sessions
printf 'set -o emacs\nalias ll="ls -alF"\n' > "$HOME/.kshrc"

How it loads: when ksh is a login shell, it reads /etc/profile and then ~/.profile. For interactive shells, it reads the file named by ENV if it exists. That’s why setting ENV="$HOME/.kshrc" in .profile is the usual pattern. To apply changes now, start a new login shell or re-exec the current one:

exec -l ksh    # current terminal becomes a login ksh
# or open a new ksh login shell with:
ksh -l

Tip: to verify whether you’re in a login ksh, check the command name. If it begins with a dash, it’s a login shell.

ps -o args= -p $$

Recommended Answers

All 4 Replies

No, it is not required to have and depends on the shell you're using. For example bash uses .bash* prefixed files:

sk@sk:~$ ls -al .ba*
-rw------- 1 sk wheel 148196 Sep 24 14:18 .bash_history
-rw-r----- 1 sk wheel    509 May  9  2005 .bash_profile
-rw-r----- 1 sk wheel   1093 Oct 15  2004 .bashrc

There is also global profiles for most shells:

sk:/etc# ls -al bash.bashrc
-rw-r--r-- 1 root root 1127 Mar  4  2005 bash.bashrc

You can also just cd to return to your home directory:

sk@sk:/var/lib$ cd
sk@sk:~$

i use korn shell, ksh

Here is the ksh login logic:

If the shell is invoked by exec(2), and the first character of argument zero ($0) is -, then the shell is assumed to be a login shell and commands are read from /etc/profile and then from either .profile in the current directory or $HOME /.profile, if either file exists. Next, for interactive shells, commands are read from the file named by performing parameter expansion, command substitution, and arithmetic substitution on the value of the environment variable ENV if the file exists. If the -s option is not present and arg and a file by the name of arg exits, then it reads and executes this script. Otherwise, if the first arg does not contain a /, a path search is performed on the first arg to determine the name of the script to execute. The script arg must have execute permission and any setuid and setgid settings will be ignored. If the script is not found on the path, arg is processed as if it named a built-in command or function. Commands are then read as described below; the following options are interpreted by the shell when it is invoked:

Files used:

/etc/passwd
/etc/profile
/etc/suid_profile
$HOME /.profile
/tmp/sh*
/dev/null

ksh man page

i cant add to your reputation for today, i will tomorrow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.