5 votes

shell script running inside devcontainer Syntax error: "(" unexpected

You are running that using sh which is not bash and does not support arrays. Use bash instead of sh and it should work fine. Alternatively, add a shebang line to the beginning of your script: #! /bin/...
  • 228k
1 vote

printing prime number in bash

Arithmetic evaluation in bash uses $(( ... )) so your test would need to be if [[ $((($a-1) % 2)) -eq 0 ]]; then ... but variable expansion is implicit in an arithmetic context, so you could write ...
  • 76.1k
1 vote
Accepted

Using a variable in between ' 's

Parameter expansion is not performed inside single-quotes. It is performed inside double quotes though, so: convert "%d.jpg[1-$pages]" combined.pdf In any case, you need some form of ...
1 vote

How do I keep a Bourne shell script running despite any error?

It's a POSIX requirement that a such a failure must abort the shell: If no readable file is found, a non-interactive shell shall abort Therefore your only option is to protect the command by ...
  • 101k
1 vote
Accepted

How to kill master script from slave script?(in bash)

At least on Linux, you can have the child script kill the process group of the parent. That will kill the parent itself and any child processes it may have launched. From man kill: ARGUMENTS ...
  • 228k
1 vote

How to kill master script from slave script?(in bash)

Clearly hackish, but to answer the question: you can reach the parent bash script by $PPID. $ cat > A.sh #!/bin/bash /bin/bash B.sh echo "A continues" exit 0 $ cat > B.sh #!/bin/bash ...
  • 101
1 vote

Direct output from gnome-terminal to text file

Correct Answer It's very likely you don't need to use gnome-terminal to achieve whatever you're doing. There most likely is a better way to capture the output of ./program than running it in gnome-...
  • 19.3k
1 vote
Accepted

Selectively extracting files of gzipped archives into new directories whose names are derived from the archive's filename

If you're using bash (not ash or similar POSIX-limited shell), you could do something like this: for f in ./*.tar.gz; do dir="../extracted/${f/%.tar.gz}" mkdir -p "$dir" echo ...
  • 73.5k
1 vote

Selectively extracting files of gzipped archives into new directories whose names are derived from the archive's filename

Untested, but should get you in the right direction: for f in *.tar.gz; do echo "Processing $f" BaseName=${f::-6} mkdir ../extracted/$BaseName tar -x -f $f -C ../extracted/$...
  • 866

Only top scored, non community-wiki answers of a minimum length are eligible