Unix: Trying to increment a calender year and display [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 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";

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}.

How to use min in formula [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
How to min inside the formula to evaluate using eval().
[5,6].min works fine but it doesn't work inside the formula eval([5,6].min*5).
Here is a way using #eval. But why you need #eval ?
eval('[5,6].min * 5')
# => 25
Simply [5,6].min * 5 will work for you.
You don't need eval.
[5,6].min*5.

Reuse of the same variable wit using echo and cut [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
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).

Alternate a BASH variable by Date [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
What method can one use to alternate a variable which is dependable by time?
For example, this week var = Office, then next week var = Oncall?
The resulting script will be using crontab to output the contents of var depending on which week it was.
Thanks.
You can use date +%W to check what week number of the year it is (starting Monday).
You can alternate between the two with e.g.
if (( $(date +%W) % 2 ))
then
var=Office
else
var=Oncall
fi

Resources