Reuse of the same variable wit using echo and cut [closed] - bash

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm try to make a script for checking some ethx.
If the eth is up and connected my script is working
When its not working I have a problem.
RESD=$(ssh -q vmx#$1 cat /sys/class/net/$3/dormant)
I get in RESD the following result:
cat: /sys/class/net/eth3/dormant: Invalid argument
I want to put in RESD now the first letter.
How can I do this?
Thanks

As per the comment above, this what you want to do: RESD=${RESD:0:1}? This is pure bash equivalent of RESD=$(echo $RESD | cut -c1).

Related

tracing multi-line commands in bash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Using the uprobe example for hooking bash's readline gives one line at a time. What/How should I hook to get multi-line commands?
I tried hooking add_history but that gives me only one line.
Example input:
cat EOF
x
<< EOF
ls \
| grep

How to do arithmetic in bash when the operator is stored in a variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
add=+
echo "$((1{$add}2))"
If I write 1+2 it outputs 3, but when I store the + sign in a variable called "add" and then use it in place of + operator, it just outputs it as if it was a string. How can I use the variable and still make it output 3?
As far as I can see, the code is wrong and should not print anything but an error.
What you should do is write the variable as ${add}, not {$add}.

Specify a particular machine name on slurm [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Hello does someone know how to specific on a slurm file which worker (machine) I want to use ?
Thank for your help
You can specify the nodes that you would like to select with the --nodelist option:
sbatch --nodelist=myHosts[1-5,7] script.sh
More details are described here.
A shorthand version of --nodelist is -w.

cutting a particular part of a line without using grep command [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
RPO.RE4_SND_MSG_RECO_Q_n_message
i have an line like this. I would like to cut till RPO.RE4_SND_MSG_RECO_Q . when i used
cut -d '_' _f4
it gave oly RECO as output .please help me Newbie to unix
You can use:
s='RPO.RE4_SND_MSG_RECO_Q_n_message'
cut -d_ -f1-5 <<< "$s"
RPO.RE4_SND_MSG_RECO_Q

Unix: Trying to increment a calender year and display [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a unix assignment and What I have isnt working right. It doesnt format like the normal "cal" function.
#!/bin/bash
d=`date '+%Y'`;
$((++d));
calstr=`cal $d`;
echo $calstr;
You don't need the $ in line 2, and you need to wrap the $calstr in double quotes:
#!/bin/bash
d=`date '+%Y'`;
((++d));
calstr=`cal $d`;
echo "$calstr";

Resources