LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Added stuff into profile.d-folder, couldn't login afterwards (https://www.linuxquestions.org/questions/linux-newbie-8/added-stuff-into-profile-d-folder-couldnt-login-afterwards-4175633497/)

cuintilo 07-07-2018 09:19 AM

Added stuff into profile.d-folder, couldn't login afterwards
 
Hello, everyone.

Recently I started using gnu/linux, specifically newest release of Debian (stretch).

Some days ago I started to learn about scripting, though for what I've seen it's synonymous with using system to it's fullest potential...

Anyway, I'm reading couple tutorial ebooks at the moment and ran into stuff I don't understand.

I tried to add a simple script displaying a message upon login, but when I tried to login (into GUI, mind you) it wouldn't let me - screen just reverted back into giving my user password after entering it.

What I did was I added simple "greeting.sh"-file into profile.d folder, which had just an echo statement in it.

Does more experienced user have an explanation for this behavior? Also some tips for good (free) ebooks about scripting and system in general would be appreciated, I'm not sure if my current reading is doing the trick efficiently enough.

Cheers, and thank you!

keefaz 07-07-2018 10:30 AM

If you login with gui, it's preferable to use startup scripts folowing your Desktop environment practices
scripts in /etc/profile.d are meant essentially to set environment (env variables, maybe functions as well)

For greeting in console login, there is /etc/issue configuration file as well

A simple echo "something" in script shouldn't produce what you describe though, there must be an error somewhere

hazel 07-07-2018 10:35 AM

You didn't put an exit command at the end of your script, did you? These scripts are "sourced" (i.e. run inside your login shell, not as a separate command), so "exit" will log you out again.

cuintilo 07-07-2018 11:25 AM

Quote:

Originally Posted by keefaz (Post 5876677)
If you login with gui, it's preferable to use startup scripts folowing your Desktop environment practices
scripts in /etc/profile.d are meant essentially to set environment (env variables, maybe functions as well)

For greeting in console login, there is /etc/issue configuration file as well

A simple echo "something" in script shouldn't produce what you describe though, there must be an error somewhere

Ok, thank you for information!

Quote:

Originally Posted by hazel (Post 5876679)
You didn't put an exit command at the end of your script, did you? These scripts are "sourced" (i.e. run inside your login shell, not as a separate command), so "exit" will log you out again.

That actually might be it, not 100% certain though, stupid me didn't save that script anywhere when I removed it from profile.d so that I could log in with gui again. Another thing that occurred to me is that I maybe forgot to add #! at the beginning. Could that produce something like this on its own? I find it somewhat confusing that sometimes when I've written something into file it doesn't seem to matter whether for example "!#/bin/bash" is there and file can be executed properly. Is this some kind of automation by something by any chance? I'm currently using emacs as my text editor with hardly any modification of my own, so there might be some kind of newbie mechanic in use?

keefaz 07-07-2018 11:31 AM

It's "#!/bin/bash" (note position of # and !), called "shebang"

Its role is to ensure that bash will interpret this script, say if you start the script from csh shell, the script will stay a bash script thanks to the bash shebang on first line

cuintilo 07-07-2018 11:38 AM

Quote:

Originally Posted by keefaz (Post 5876692)
It's "#!/bin/bash" (note position of # and !), called "shebang"

Its role is to ensure that bash will interpret this script, say if you start the script from csh shell, the script will stay a bash script thanks to the bash shebang on first line

So if I have a (bash) thing that's missing it it would be running properly in a bash and any other environment that recognizes notation and anything else would produce errors that produce some sort of message/termination?

keefaz 07-07-2018 11:43 AM

Yes if started from a bash shell, a bash script doesn't need the shebang


All times are GMT -5. The time now is 10:37 AM.