Re: Bash: testing a variable

2021-07-09 Thread Charles Curley
On Fri, 9 Jul 2021 16:53:45 -0400 Greg Wooledge wrote: > Since it's a function, and not a script, there's no shebang. So I'm > guessing shellcheck assumed it was /bin/sh code, rather than bash > code. <<< is just one of the bashisms I used here. local is > another. The use of arrays is a third

Re: Bash: testing a variable

2021-07-09 Thread Greg Wooledge
On Fri, Jul 09, 2021 at 11:40:36PM +0200, john doe wrote: > On 7/9/2021 9:54 PM, Charles Curley wrote: > > # if [[ ! ${PATH} =~ .*/home/charles/.local/bin.* ]] ; then > > [[ $PATH =~ \/home\/charles\/... ]] && echo match || echo nomatch > > That is, escaping the backslash. First, you are escapin

Re: Bash: testing a variable

2021-07-09 Thread john doe
On 7/9/2021 9:54 PM, Charles Curley wrote: I'd like to check two things: * Whether a given path is not already in the $PATH variable * Whether the given path already exists If both are true, I'd like to add the given path to the $PATH variable. I can add the given path, and test for the exist

Re: Bash: testing a variable

2021-07-09 Thread Greg Wooledge
On Fri, Jul 09, 2021 at 02:45:23PM -0600, Charles Curley wrote: > On Fri, 9 Jul 2021 16:25:11 -0400 > Greg Wooledge wrote: > > > add_path_maybe() { > > local p i > > ... > > Very nice, sir. Thank you. > > shellcheck complained about the redirection in the "IFS=: read" line, > but I'm not goin

Re: Bash: testing a variable

2021-07-09 Thread Charles Curley
On Fri, 9 Jul 2021 16:25:11 -0400 Greg Wooledge wrote: > add_path_maybe() { > local p i > ... Very nice, sir. Thank you. shellcheck complained about the redirection in the "IFS=: read" line, but I'm not going to worry about that. -- Does anybody read signatures any more? https://charlescu

Re: Bash: testing a variable

2021-07-09 Thread Charles Curley
On Fri, 9 Jul 2021 22:11:05 +0200 Joerg Kampmann wrote: > > I call the script with the . operator: ". test.sh" > this is the result: > > > root@primergy:~/software-env# . test.sh > > Substr is /root/.local/bin/ > Substring NOT found. > root@primergy:~/software-env# OK, that's what I get if

Re: Bash: testing a variable

2021-07-09 Thread Kampmann
I am sorry I found myself in the wrong thread ... so discard Am 09.07.21 um 22:25 schrieb Greg Wooledge: On Fri, Jul 09, 2021 at 01:54:19PM -0600, Charles Curley wrote: I'd like to check two things: * Whether a given path is not already in the $PATH variable * Whether the given path already e

Re: Bash: testing a variable

2021-07-09 Thread Greg Wooledge
On Fri, Jul 09, 2021 at 01:54:19PM -0600, Charles Curley wrote: > I'd like to check two things: > > * Whether a given path is not already in the $PATH variable > > * Whether the given path already exists > > If both are true, I'd like to add the given path to the $PATH variable. add_path_maybe(

Re: Bash: testing a variable

2021-07-09 Thread Joerg Kampmann
Am 09.07.21 um 21:54 schrieb Charles Curley: I'd like to check two things: * Whether a given path is not already in the $PATH variable * Whether the given path already exists If both are true, I'd like to add the given path to the $PATH variable. I can add the given path, and test for the e

Bash: testing a variable

2021-07-09 Thread Charles Curley
I'd like to check two things: * Whether a given path is not already in the $PATH variable * Whether the given path already exists If both are true, I'd like to add the given path to the $PATH variable. I can add the given path, and test for the existence of the given path. I can write expressio