Saturday, April 27, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1194  / 1 Year ago, mon, january 30, 2023, 4:05:03

I have run across an issue that I just cannot seem to figure out. When I start my terminal in ubuntu (14.04) I get the message



sdfsdfsdi: command not found


As you can see it just looks like someone (maybe myself) was banging the keyboard in frustration and then accidentally wrote to some script that bash reads on initialization. The problem is I cannot for the life of me find what script bash is reading when it encounters this gibberish. I've looked in



~/.profile
~/.bashrc
~/.bash_profile
/etc/profile
/etc/bash.bashrc


and none of them seem to have the gibberish phrase. Are there other locations that bash reads from on startup that I can check?



Thanks!



Andrew



(Note this is not a critical issue, more of just a minor annoyance).


More From » command-line

 Answers
4

To find which commands bash runs on start-up and which file those commands came from, run:



PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7>&2


The output is lengthy but the source of the gibberish will hopefully be clear.



Explanation:




  • PS4='+$BASH_SOURCE> '



    When creating an execution trace, bash will prepend every line with an expansion of PS4. Here, we make PS4 display the source file that is being read.


  • BASH_XTRACEFD=7



    This sends the execution trace to 7 which is a file descriptor chosen in hopes that it is one that the bash start-up files will not mess with.


  • bash -xl



    This starts bash with the options -x, which causes all commands to be displayed with the PS4 prompt, and -l which instructs bash to treat this like a login shell. If you don't get gibberish on login shells, then try it without -l.


  • 7>&2



    This redirects the trace output back to stderr for display on the terminal.




Three Refinements



Based on Geirha's comment, this version adds three improvement:



PS4='+ $BASH_SOURCE:$LINENO:' BASH_XTRACEFD=7 bash -xlic ""  7>&2


There are three refinements here: (1) the PS4 prompt now also displays the line number as well as the file name, (2) the -i flag makes the shell interactive, in addition to -l which made it a login shell, and (3) -c "" causes the shell to exit after initialization is complete.


[#22798] Wednesday, February 1, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cheeturage

Total Points: 432
Total Questions: 111
Total Answers: 115

Location: Bahrain
Member since Tue, Mar 1, 2022
2 Years ago
cheeturage questions
Sat, Dec 4, 21, 02:22, 2 Years ago
Mon, Jan 2, 23, 22:39, 1 Year ago
Sun, Sep 12, 21, 03:21, 3 Years ago
;