history-search-backward clobbers history

2024-06-19 Thread Andreas Schwab
$ printf 'echo 1234\necho 2345\necho 3456\n' > history $ HOME=$PWD HISTFILE=history TERM=xterm bash --norc -i <<<$'\20\eb1\e[5~\nhistory\n\20\20\eb2\e[5~\nhistory' bash-5.3$ echo 1234 1234 bash-5.3$ history 1 echo 1234 2 echo 2345 3 echo 13456 4 echo 1234 5 history bash-5.

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Will Allan
> Not sure how common but this is what makes sense. Or name sourceables > foo.sh, bar.sh and executables foo, bar so they don't clash and source with > `${BASH_SOURCE%/*}' prepended to PATH and it'll work fine. >  > This feature request sounded promising at first, it feels like > bike-shedding now.

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Léa Gris
Le 19/06/2024 à 22:04, Will Allan écrivait : Since I find the accepted answer to be overly complex for my needs, I usually just do this: declare -r SCRIPT_DIR="$(dirname -- "${BASH_SOURCE[0]}")" source -- "${SCRIPT_DIR}/../lib/foo.sh" source -- "${SCRIPT_DIR}/../lib/bar.sh" ... But, I still don

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Koichi Murase
2024年6月20日(木) 5:47 Léa Gris : > Look like you did not find a proper answer there. Here is one simple > that involve no sub-shell at all and does exactly what your sub-shell > version does. > > declare -r SCRIPT_DIR=${BASH_SOURCE[0]%/*} This doesn't work as explained by Will. BASH_SOURCE doesn't co

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Will Allan
Yes, that's precisely my point. It suddenly becomes more complex and bug prone than at first glance. To do it without a subshell, I need something like this boilerplate at the top of each of my main scripts: if [[ "${BASH_SOURCE[0]}" == */* ]]; then   SCRIPT_DIR="${BASH_SOURCE[0]%/*}" else   SCR

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread konsolebox
On Thu, Jun 20, 2024 at 4:47 AM Léa Gris wrote: > realSource=$(realpath -- "${BASH_SOURCE[0]}") && > realScriptDir=${realSource%/*} `realScriptDir=$(realpath -m "${BASH_SOURCE}/..") || exit` is simpler if you don't care about versions of realpath not supporting `-m`. It is mostly convenient if y

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread konsolebox
On Thu, Jun 20, 2024 at 4:05 AM Will Allan wrote: > But, I still don’t like it. I have to start off each script with a slow > command substitution (subshell) which introduces a variable that I don’t > really want, but it’s too slow to do this repeatedly: I agree. > source -- "${BASH_SOURCE_PAT

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Will Allan via Bug reports for the GNU Bourne Again SHell
Thanks for clarifying! I wondered if I was missing something, but kept seeing `${BASH_SOURCE[0]/%/*}` suggested in the thread, which I pointed out is flawed. I guess what I want is a "BASH_SOURCE_DIR" variable or something like it, mainly to avoid the boilerplate, variable, and/or command substi

Re: proposed BASH_SOURCE_PATH

2024-06-19 Thread Oğuz
On Wednesday, June 19, 2024, Will Allan wrote: > I think this is exactly why this feature is necessary. Unless I am > misunderstanding, simply prepending `${BASH_SOURCE%/*}' to a sourced path > will not work in all cases. For example, when executing the main script > directly inside the script di