help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: i cant see whats the issue, .. ps1 + propt command + date


From: Greg Wooledge
Subject: Re: i cant see whats the issue, .. ps1 + propt command + date
Date: Thu, 23 Sep 2021 07:29:54 -0400

On Thu, Sep 23, 2021 at 10:48:46AM +0200, Alex fxmbsw7 Ratchev wrote:
> i wrote the following code in $PROMPT_COMMAND

> prptnow=$EPOCHREALTIME saveIFS IFS=. prptnow2=( $prptnow ) restoreIFS \
> dfslist=$( prptrecents )
> 
> printf -v prptnow3 '%(%F , %T)T' $prptnow2
> prptnow3+=.${prptnow2[1]}

This is incomprehensible.  Either it's utterly broken to begin with,
or else your mail user agent has removed line breaks, rendering the
code unreadable.

As it's written, you have a command named "saveIFS" which is invoked
with a temporary environment variable named prptnow.  Except that it
cannot be invoked at all, because some of your arguments which you
pass to it contain unquoted parentheses.

unicorn:~$ x=y saveIFS IFS=. prptnow2=( $SHELL ) restoreIFS
bash: syntax error near unexpected token `('

The only way this code could work is if the prptnow2=... array assignment
is on a separate line.  And if there are supposed to be line breaks in
the code, then we don't know WHERE THEY ARE.

Whatever you're using to send email, it's not compatible with programming
language syntax.

We also have no idea what "saveIFS" and "restoreIFS" are.  Are they
functions?  What do they do?

If the whole purpose of your code is to split the value of $EPOCHREALTIME
at the period, you don't need array assignments and IFS changes and
*unquoted* (!!!) parameter expansions.  You can use ${var#*.} and ${var%.*}
instead.

now=$EPOCHREALTIME
whole=${now%.*}
frac=${now#*.}
printf -v prptnow3 '%(%F , %T)T.%s' "$whole" "$frac"

I think that's what you were trying to do.  It's frustrating that we have
to *guess* what you were trying to do from mangled non-working code.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]