Linked Questions
29 questions linked to/from Are there naming conventions for variables in shell scripts?
1
vote
2
answers
3k
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.
89
votes
14
answers
52k
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
...
15
votes
2
answers
4k
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
6
answers
13k
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
2
answers
2k
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 ...
9
votes
1
answer
4k
views
Is PS1 really an environment variable?
I always thought that PS1 was an environment variable.
But when I check the default .bashrc of Ubuntu and check for PS1 with
grep PS1 /etc/skel/.bashrc
there is no export PS1.
If there is no export, ...
-1
votes
3
answers
29k
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
2
answers
26k
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.
2
votes
3
answers
7k
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 ...
5
votes
3
answers
4k
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 string....
5
votes
2
answers
11k
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
vote
2
answers
9k
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 want ...
4
votes
1
answer
2k
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
1
answer
2k
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
3
answers
2k
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"/"$...