Linked Questions

1
vote
2answers
2k 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.
77
votes
12answers
37k 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 ...
13
votes
2answers
1k views

bash script: fixed sleep time is adding up in while loop

I am new to bash scripting and started out with a few sample scripts. One is: #!/bin/bash SECONDS=5 i=1 while true do echo "`date`: Loop $i" i=$(( $i+1 )) sleep $SECONDS ...
7
votes
6answers
12k 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 ...
4
votes
2answers
1k views

What is the term to describe the naming method "MyVariable" (as opposed to "myVariable")?

Variables and procedures in JavaScript are often named via the "camelCase" naming method, as: myVariable Any letter of the only or not-only-but first letter in an expression which acts as ...
1
vote
2answers
7k 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 ...
2
votes
3answers
3k 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 ...
4
votes
1answer
1k 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}" ...
3
votes
1answer
2k 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 ...
-4
votes
3answers
12k 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....
2
votes
2answers
2k views

How can I programmatically get this layout in tmux?

I spent quite a bit of time messing around with tmux recently, and cannnot figure out what I am doing wrong. It seems to me that some layouts are simply not allowed. There is no error or warning ...
-1
votes
2answers
4k views

How to write shell script to output two variables in one line without loop

I want to write shell script to output two variables in one line. My script is: SRC = "192.168.1.1" PORT = "22" I want to make the output looks like 192.168.1.1,22 How to do this? Thank you.
0
votes
2answers
4k 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 ( ...
4
votes
1answer
962 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
3answers
451 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