How to get "$" on termux terminal? - termux

I was using termux and suddenly after I restarted it "~$" appears instead of "$". Why did this happen and how can I get $ back on terminal ?

I think either you have set PS1 or accidentally changed your shell into fish. Basically you can set PS1 for getting "$" sign.
export PS1='$ ' and add that in ~/.bash_profile as well.
if you accidentally changed your shell then get back in bash by chsh
But what is wrong with that prompt, here ~ is showing current directory that is $HOME. When you change directory it will be also change.

Related

GDB loads unfindable script on shell start

On my computer when starting a shell in GDB it would give a very standard shell (looks like "bash-4.4$")- ignoring most of my environment variables. The real problem for me is I cannot adjust the LD_LIBRARY_PATH variable because of this reason.
More posts on SO suggest to check .bashrc and .profile, I did that. I even created a new user and the problem persist. So some script is loaded by GDB changing my PS1 and unsetting LD_LIBRARY_PATH. However, I have no idea which process. For some reason Root does not have this problem.
This works:
delruej#delxps:~$ export LD_LIBRARY_PATH=Hello
delruej#delxps:~$ bash
delruej#delxps:~$ echo $LD_LIBRARY_PATH
Hello
However this does not:
delruej#delxps:~$ export LD_LIBRARY_PATH=Hello
delruej#delxps:~$ gdb
(gdb) shell
bash-4.4$ echo $LD_LIBRARY_PATH
It should be some script loaded by every user, but not by root.
So some script is loaded by GDB changing my PS1 and unsetting LD_LIBRARY_PATH
No. GDB just loads your $SHELL, and your $SHELL unsets these environment variables for some reason.
You should look at values of $SHELL and possibly $ENV.
Note that:
Using LD_LIBRARY_PATH is generally a mistake; you should strive to build your programs such that they don't require it.
You can set any environment variable inside GDB (you don't have to inherit them from parent shell) with (gdb) set env FOO bar.
I purged GDB, removed /usr/share/gdb/, reinstalled and the problem was fixed.

How to make Midnight Commander exit to its current directory

I've been using, in equal amounts, Fedora and Ubuntu for well over a decade now, and there's one minor but irritating difference I noticed from their installs of midnight commander. When you change dirs inside it using Fedora, then exit, it has done the chdir for you but in Ubuntu it keeps it at the place you started. Googling threw up a solution for older Ubuntus here: http://ptspts.blogspot.co.uk/2010/01/how-to-make-midnight-commander-exit-to.html but trying that fails on 16. When I say fails, I mean the commands are accepted without complaint but it doesn't change mc's behaviour in Ubuntu.
The other responses are fine, but I feel like they are unsatisfying, here is my solution, which I think is the simplest:
Put this line into your ~/.profile
alias mc='source /usr/lib/mc/mc-wrapper.sh'
Create an executable with the following content:
MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$"
/usr/bin/mc -P "$MC_PWD_FILE" "$#"
if test -r "$MC_PWD_FILE"; then
MC_PWD="`cat "$MC_PWD_FILE"`"
if test -n "$MC_PWD" && test -d "$MC_PWD"; then
cd "$MC_PWD"
fi
unset MC_PWD
fi
rm -f "$MC_PWD_FILE"
unset MC_PWD_FILE
Then define an alias pointing to that executable:
alias mc='. ~/.config/mc/exitcwd'
Don't forget to apply the alias:
source ~/.bashrc
Simple:
mcedit ~/.profile
Add this line at the end of file:
alias mc='source /usr/lib/mc/mc-wrapper.sh'
Type this command to execute changes
source ~/.profile
Then, to save both sides of mc windows, click at the top of MC
Options -> Panel options -> Auto save panels setup
Here, in the article Use Midnight Commander like a pro, explains how to do it.
Basically, you have to create an alias for mc-wrapper.sh.
While it's not exactly an answer to your question: just use ctrl+o to drop to the shell. It doesn't really quit mc, but that has the benefit that you can just hit ctrl+o again to go back where you were in mc.
For Ubuntu put this to .bashrc:
alias mc='. /usr/lib/mc/mc-wrapper.sh'
then:
source ~/.bashrc
(or relaunch the console)
I want to add that this only works by existing with F10. If you exit by typing exit the path will not be preserved.

system("history") not working

I've run into a snag, I'm trying to implement a linux shell program of sorts with C++ and many of my commands seem to work, however, when I try to get the history(list all recently executed commands) I get an error of "sh: 1: history: not found" the below line is all that runs in the area, what is the issue?
system("history"); //produces the error above ^
If I do
$ history
from the command line it's fine...why is it not fine in C++?
system executes a program using /bin/sh, but history is a bash builtin.
You might look at the contents of ~/.bash_history instead. (Note (by leemes) .bash_history is only updated after closing a previous bash session, as well as it is not updated by executing a command with system.)
Because it's a bash shell builtin not necessarily accessible through /bin/sh -c` (which may be the bourne shell).

python getlocale function is not working in eclispse/pydev, but works fine in Terminal

When i tried to run following python code:
setlocale(locale.LC_ALL,"")
print getlocale()
The result is that it works fine if i run the script from Terminal.
But in eclipse/pydev with the same python compiler(python 2.7),it always return (none,none), any idea?
As you have already guessed from our conversation in the comments, this behavior is related to the environment. If you run Eclipse from the Terminal, you will get the same results you get when running Python directly from the Terminal.
So, your program is actually working fine. Depending on what you want to do, you don't need to worry about anything.
However, if you want to reconfigure your environment (system-wide or for all programs launched from the GUI, for example), you can do that in the appropriate files, using this answer as a guide.
For example, you may want to set the variables LANG and LC_ALL in one of those files, mimicking the configuration that is shown when you run the command locale from the Terminal. Assuming you want en_US with UTF-8, that added lines would look like:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

nohup ./startup & Permission Denied

I successfully compiled a MUD source code, and it says in the instructions to start up the server using
nohup ./startup &
although when I do this it gives me this error:
$ nohup: ignoring input and appending output to `nohup.out'
nohup: failed to run command `./startup': Permission denied
I have looked all over the internet to find the answer. A few of them said to put my cygwin directory in the root folder (I am using windows 7) and its directory is C:\cygwin
so thats not a problem.. Can anyone help me with this please??
Try chmod +x startup, maybe your startup file is not executable.
From "man nohup":
If the standard output is a terminal, all output written by the named
utility to its standard output shall be appended to the end of the
file nohup.out in the current directory. If nohup.out cannot be
created or opened for appending, the output shall be appended to the
end of the file nohup.out in the directory specified by the HOME
environment variable. If neither file can be created or opened for
appending, utility shall not be invoked. If a file is created, the
file's permission bits shall be set to S_IRUSR | S_IWUSR.
My guess is that since "sh -c" doesn't start a login shell, it is inheriting the environment of the invoking shell, including the HOME environment variable, and is trying to open it there. So I would check the permissions of both your current directory and $HOME. You can try to touch test.txt in current directory or $HOME to see if you can perform that command.
As staticx writes, check the permissions of the directory (and the user) - and the executable.
Instead of using nohup:
check if nohup is needed at all, try ./startup </dev/null >mud.out 2>mud.err &, then close the terminal window and check if it is running
or just run ./startup in a screen session and detach it (<ctrl>+<a>,<d>)