All Questions
Tagged with programming bash
32 questions
1
vote
2
answers
1k
views
Is there a way to do namespaces like in C for bash?
What I'm talking about is like in C, you get to use namespaces with the statement using namespace blah blah blah, can you do the same thing but in bash?
4
votes
2
answers
13k
views
Creating a bash script to install packages
I'm quite a newbie when it comes to bash. I'm trying to create a script that checks whether a package is installed or not. If not it will install that package. Not sure what I'm doing tbh.
#! /bin/...
0
votes
3
answers
97
views
Quoting rules in a complex situation
When writing lines of code we sometimes need to consider escaping some characters.
I have come across a situation that I cannot answer on my own
In PHP, the exec command requires a string enclosed in ...
0
votes
4
answers
165
views
Scoring from input in Bash
Can you help me please?
I have a task. I have from input some text with numbers. For example:
beta 1
score 9
something 2
beta 4
something 1
I need to calculate all numbers with the same ...
0
votes
1
answer
909
views
Bash script printing expression instead of result
I am trying to calculate multiplication of number of arguments and first argument provided by the customer. here the arguments are 10, 15 so total number of arguments is 2. Now i want the shell to ...
1
vote
1
answer
415
views
Ensuring only 1 mandatory parameter is passed to script
I am writing a shell script and new to getopts for parameter parsing.
What I have are 1 optional and 2 mandatory parameters and what I want to do is ensure that only one mandatory parameter is passed. ...
1
vote
1
answer
57
views
how to repeat values of B variable till number of A variables are finished
I have infile with values for 2 variables
# cat infile
A 1
B 2
C
D
E
I want to read variable a & b, so that if $b has null value, it should repeat like 1..2,
till all $a values are read.
so if I ...
0
votes
2
answers
140
views
using command subsitition in a bash for loop
I am probably making an obvious mistake but I could use a strong hint:-)
for file in *; do ls $file | var=$(ls $file | grep -Eo '.{18}$' | cut -d '.' -f1 |sed 's/.\{12\}/&./'); echo "var is $...
0
votes
1
answer
409
views
Flip-flop in shell
In Wikipedia there are two relevant articles about the term "Flip-flop":
Flip-flop (electronics)
Flip-flop (programming)
I think that there is a formal-logic common denominator between the ...
0
votes
2
answers
7k
views
How to get into python environment and run some python commands and return to normal terminal using shell script
Sorry about the title it may not be clear. Here is the complete explanation of my doubt. I am writing the below shell script and expecting the mentioned output.
#!/bin/bash
python3
print("Hello ...
0
votes
0
answers
190
views
End process but resume bash script?
I am trying to create a script in which part of it runs a command that can only be stopped by the user sending SIGINT to the process. I want the user to be able to press Ctrl+C to end that part of the ...
1
vote
0
answers
26
views
How to give stdout to different program on same line? [duplicate]
I could do it long way i.e
cat hi.txt | grep 'important url' > imurl
cat hi.txt | grep -v 'not important url' > imnoturl
cat hi.txt | otherprogram1
cat hi.txt | otherprogramN
However, is there ...
1
vote
1
answer
5k
views
Simple shell loop fail in Makefile
Why does the shell loop
l='abc de f'; for k in $l ;{ echo $k; }
inside Makefile not work ?
instead only give
abc de f
at once
How to solve such in the definitive way?
1
vote
1
answer
759
views
How do I pass commands to an external command, from bash?
I would like know if it is possible to enter in an external program and give commands from a bash script.
As an example, lets imagine the external program is ipython and I want to give the commands
...
0
votes
1
answer
599
views
Bash Script Time each function and Time total Script Execution Duration
I've written a bash script and would like to implement a timer that will also get the total time of the scripts execution duration and also the time that each loop iteration takes. For example, in the ...