0

I know that by principle, one shouldn't change .bashrc and common changes like creating an alias should better be done in .profile instead.

When I rent a new IaaS system with Bash as main shell, the first step I take is (an extended version) of this:

cat <<-EOF >> "$HOME"/.profile

    set -x && complete -r
EOF

source "$HOME"/.profile

The extra empty line there between the "routine" to the "subroutine" content is because .profile already includes some data, and I want to separate the new data I append (which can be more than the single line of set -x && complete -r) from the rest of the already-present data.

I need another file, one that comes empty but also acts as a "boot file" similarly to .bashrc and .profile to which I can append the data without an extra empty line. A quick look in my user's directory in Ubuntu 16.04 (xenial) shows no such file.

Is there a file like I desire in another directory or should I create one myself? If so, please only hint how it should be done

  • 3
    Not an answer, since I'm questioning one of your assumptions. Why do you not want to change your (own) .profile or .bashrc? – Jeff Schaller Dec 14 '18 at 1:33
  • Have you researched /etc/skel? – eyoung100 Dec 14 '18 at 2:13
  • @eyoung100 after you mentioned it. I understand it uses to set the structure of a new user's directory, but I already created my user and doesn't want to create a new one... – JohnDoea Dec 14 '18 at 2:45
  • @JeffSchaller First, by principle I'd like to avoid hanging existing shell-direction files as much as I can. Secondly, and as absurd as it can be grasped - I prefer to save this extra line – JohnDoea Dec 14 '18 at 4:04
  • @JohnDoea I'm not saying create another user. Consider reading the file in: /etc/skel/.profile Create a template etc, cat it in then save the result to your .profile – eyoung100 Dec 14 '18 at 4:46
5

I know that by principle, one shouldn't change .bashrc and common changes like creating an alias should better be done in .profile instead.

This doesn't make any sense. You probably misunderstood what you read. There is no reason why you shouldn't change .bashrc. On the contrary, this is your customization file. It's there precisely so that you can put whatever you want in it. You don't have to keep whatever was there at the beginning, and you can add what you want.

.profile and .bashrc are both your customization files, but they have different roles. .profile is for login-time things like environment variables. .bashrc is for shell configuration like aliases and completion settings.

set -x is for debugging only. complete -x is a shell customization, not a login-time setting, so it goes into .bashrc.

I need another file, one that comes empty but also acts as a "boot file" similarly to .bashrc and .profile to which I can append the data

If for some reason you want to keep whatever was there at the beginning but don't want to continually modify the existing files, then you can create other files, and put an instruction in .profile and .bashrc to include your file. In both .profile and .bashrc, you can use the command . (nicknamed “dot”) followed by a file name to read instructions from that file. For example, if you want to put all your customizations in a directory called etc so that you can quickly deploy it, then here's what you can do:

  • Login-time things such as environment variables go into ~/etc/profile.
  • Bash customizations go into ~/etc/bashrc.
  • Your first-time deployment code can be something like this.

    rsync -a remote-deployments/etc mynewhost.example.com/etc
    ssh mynewhost.example.com -c <<'EOF'
    grep -q -s -F '~/etc/profile' ~/.profile || echo '. ~/etc/profile' >>.profile
    grep -q -s -F '~/etc/bashrc' ~/.bashrc || echo '. ~/etc/bashrc' >>.bashrc
    EOF
    

without an extra empty line.

You chose to put an empty line there. It doesn't hurt anything. There is absolutely no reason not to put an empty line. But if you don't want an empty line, it's your choice. Don't put it there.

  • +1 Gilles, one small thing, please; complete -r seems to work great for me from .profile; if I understand you correctly, philosophically it should be in .bashrc but there is no prevention to put it in .profile as an exception, so it shouldn't hurt, right? – JohnDoea Dec 16 '18 at 3:04
  • @JohnDoea If you put it in .profile, it'll cause an error if .profile is executed by a different shell (which may not matter to you if you only ever log in with SSH) and it won't take effect if you run a non-login shell (e.g. in screen or tmux). It's a practical difference, not a philosophical difference. – Gilles Dec 16 '18 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.