gnuplot: Can you set shell variables in a script and then later call them?

I want to be able to issue shell commands from a gnuplot script, such as setting a variable, but it appears that the system command spawns a new shell instance as opposed to issuing commands to the shell instance which is running the gnuplot script. See the following script where the first line allows assignment of $foo, but the second line cannot access that variable. In this case, $foo is assigned as an arbitrary string as opposed to a reference to the directory, hence the "

#!/usr/bin/gnuplot -p
system "export foo="$HOME/path/to/dir";echo $foo"
system "echo $foo"
set datafile separator "t"
#plot "`echo $foo`/bar.dat" using 2:3
plot "<( sed '5p' $foo/bar.dat )" using 2:3

Go to Source
Author: T. Zack Crawford

How to change value from first line in one newly added column

I have a file named file1.txt where below data is there

Job1        20200731    Post          NOTOK
Job2        20200731    Post          NOTOK
Job3        20200731    Post          NOTOK
JOb3        20200731    Post          NOTOK
Adding one new column using below command

awk -v column=4 -v value=”four” ‘BEGIN {FS = OFS = “ttt”;}{for ( i = NF + 1; i > column; i– ) {$i = $(i-1);}$i = value;print $0;}’ file1.txt

Job1        20200731    Post          NOTOK                   four
JOb2        20200731    Post          NOTOK                   four
Job3        20200731    Post          NOTOK                   four
JOb4        20200731    Post          NOTOK                   four

Here adding three "t" character. First line "four" should be spaced with APPLICATION_STATUS with just one t and first line "four" should be replaced with "CYCLE_NUMER"

Desired output
Job1        20200731    Post          NOTOK                 four
JOb2        20200731    Post          NOTOK                 four
Job3        20200731    Post          NOTOK                 four
JOb4        20200731    Post          NOTOK                 four

Go to Source
Author: Sourin Biswas

How to obtain the path of a Bash script, when it’s executed through a symlink?

I want to obtain the path of a Bash script, is when it’s executed through a symlink.

In this case, $0 is -bash, while BASH_SOURCE is the symlink’s path.

Can I obtain the script’s path through some shell variable, built-in shell command, or external command?

Will BASH_SOURCE always holds the initial symlink’s path, even if the script is executed through several levels of indirection (multiple symlinks)?

Could I use ls with BASH_SOURCE to always retrieve the script’s path?

Go to Source
Author: Shuzheng

How do I rename files multiple files by removing everything but numbers?

I want to rename files like:

SL Benfica vs. SC Beira-Mar 136.mp4
SL Benfica vs. SC Beira-Mar 137.mp4
SL Benfica vs. SC Beira-Mar 138.mp4
SL Benfica vs. SC Beira-Mar Jogo 074.mp4
SL Benfica vs. SC Beira-Mar Jogo 082.mp4
SL Benfica vs. SC Beira-Mar Jogo 112.mp4

But this

for f in *.mp4; do echo mv "$f" "${f//[^0-9]/}.mp4"; done

Adds a “4” at the end:


I think that it gets confused with the “4” in “mp4”. How can I solve this?

Go to Source
Author: mykahveli

SSH Time out Error

I am looking for new ideas on how can I do more better.

Home laptop (home Laptop can access only Linux VM)
Linux VM (This machine can access only jump box)
jump box VM

I can ssh fine from Linux VM to jump box keys are setup.

one user is set up in Linux VM called joe and Joe .bash_profile looks like this.

ssh || ssh

Note: There is two nic on jump box if one is down we can use the other nic for login.

Let’s say first nic is down and when I do telnet from my home laptop (telnet Linux VM) and provide user name joe it should automatically connect us to but one is down it’s giving message timeout and taking a long time to connect to other nic.

is there any way when I do telnet and give user name check first ssh connection if down automatically connects to other second one like in 2-3 secs?

Right now it will give us a message

Time out
time out
time out
And then it will try to connect the second nic.

I can more clarify if you guys have any more questions for me.

Go to Source
Author: John


Resolving hosts can add up to the connection attempt, so specifying an IP address directly can shave off some of those precious milliseconds. If it’s only in a local network with the IP addresses all laid out that should not be the case. At least that’s what I think.

Perhaps explicitly setting the ConnectTimeout option to a shorter one. Like so,

ssh -o ConnectTimeout=10 user@host

This can help. Adjust the number to a sweet spot that works for your ssh setup as necessary.

Catch signal when a command fails

I’m trying to build a shell that gives you suggestions if you have a typing error, but I’m having trouble to catch the error.

The user will type something and after parsing it, I will use the execvp() function. The problem I’m having is that if the command is wrong I need to catch that error. I was thinking to use a signal handler, but first I need to know what signal does the bash send when a process uses a command incorrectly.

Go to Source
Author: alvarogv

How can I configure ZSH to start each shell with an isolated, empty history?

I use ZSH with Oh My Zsh. I would like each new ZSH shell to start with an empty history. Commands typed in one shell should never show up in the history of another shell. How can I achieve this?

I’ve tried appending the following to my ~/.zshrc to no avail:

setopt no_share_history
unsetopt share_history
unsetopt inc_append_history
unsetopt append_history

I have also tried following this answer to make the arrow keys only show local history, but that seemed to have no effect.

Currently, if I open a new shell, it imports history. I cannot seem to delete the history; when I delete ~/.zsh_history, it re-appears with the entire old content once I open a new shell. inc_append_history does prevent history from being written right away, but the history will still eventually be saved once the shell is closed.

Go to Source
Author: bgfvdu3w

how to append a string at the end of a line but also before some n characters

  • List item

how to add some string at the end of the line in a file : But also before 3 charcters .

I tried but ended up by appending at the last of the string .can anyone help me pls

Example :

content :
line1 :a
line2 :bbbb
lin3: vvvvv
line4: cccccc
line5: dd
line6 :rules(‘test’, ‘.*’, [abc,bcd]).

i tried using
sed -i ‘/rules/ s/$/ ***/’ file1.txt

rules(‘test’,[abc,bcd]). ***

But preffered o/p:

Go to Source
Author: yugandhar