Linked Questions

1
vote
2answers
1k views

What are the specific naming conventions for variables in bash shell scripting language? [duplicate]

Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
56
votes
11answers
19k views

Why write an entire bash script in functions?

At work, I write bash scripts frequently. My supervisor has suggested that the entire script be broken into functions, similar to the following example: #!/bin/bash # Configure variables ...
5
votes
6answers
9k views

Check command success in bash

I'm currently writing a small script to backup bulks of floppy disks and format them afterward for later use. I use dd to copy the disk's image and cp to copy all the files on the disk. Here are the ...
1
vote
2answers
4k views

Bash can't run command from script: mkdir command not found [closed]

I have separate scripts for tasks in bash. Here is the broken one: #!/bin/bash PATH=/home/name/ mkdir $PATH cd $PATH && echo "done." exit 0 Today it broke and first time it simply didn't ...
4
votes
1answer
424 views

Passing args from the bash script to the function in the script

My script: #! /bin/bash -- set -x ## docker-compose wrapper compose_fn() { local ENV="${1}" local VERB="${2}" local SERVICE="${3}" local CMD="docker-compose -f ${ENV}.yml" case "${VERB}" ...
-4
votes
3answers
3k views

How to download all files of a GitHub project with wget (in raw form)? [duplicate]

How to download all files of a GitHub project with wget? All files should be downloaded in their raw form. Already tried: wget -P ~/ https://raw.githubusercontent.com/u/p/b/* wget -P ~/ https://raw....
1
vote
1answer
680 views

How do I join an array of strings where each string has spaces?

My bash script: #!bin/bash MY_ARRAY=("Some string" "Another string") function join { local IFS="$1"; shift; echo -e "$*"; } join "," ${MY_ARRAY[@]} I want the output to be: Some string,Another ...
2
votes
3answers
307 views

Iterate through multiline string line by line

I would like to process a multiline string and iterate it line by line, in a POSIX shell (/bin/sh) on a BSD platform. Bash is not included in the base BSD-distribution and has a GPL license - so I am ...
0
votes
2answers
2k views

Sleep command to run after exactly every one hour

I need your small help, i have one script which i can not schedule on crontab. But I am using sleep command. I am facing issue while using sleep command. My script took 10 or 15 min to complete ( ...
3
votes
1answer
262 views

How to use variables inside back-quotes

I have a bash script that accepts a parameter "$input" and (among other things) directs it into a program and collects the output. Currently my line is: OUTPUT=`./main.exe < $input` But I get ...
0
votes
2answers
407 views

Eval and exec with variable substitution

I'd like to execute a statement to start a server. For that I have an environment variable to determine which server is to be started. I was given this command as a starting point: eval "exec ...
0
votes
2answers
314 views

Extract filename and substitute

I am extracting the filename part from a full path as follows: PATH=/a/b/c/foo.o #1 BASE=${PATH##*/} #2 BASE=${BASE/%.o/-1234.o} #3 echo "$BASE" Is there a way to merge #2 and #3? Whenever I ...
-1
votes
2answers
81 views

What does this command do (strange assignments and redirections) [closed]

I would like to get more details on what the below command is doing: PASSING=0 FAILED=0 > log_${ENV} print "Test Started at `date`\n"
0
votes
3answers
107 views

Duplicate elements of an array except the first and last elements

I have an array, and I would like to repeat each element except the first and last elements. For example if the array has five elements 1 2 3 4 5, then after repeating, its elements should be 1 2 2 3 ...
0
votes
3answers
64 views

Which quoting style GNU Bash variable definitions (mostly for paths)? [closed]

Which of the following quoting styles, for GNU Bash variables, is preferred and why? Two double quotes: VAR="/path/$V1/path with space/$V2". Multiple double quotes: VAR=/path/"$V1"/"path with space"/"...

15 30 50 per page