Questions tagged [syntax]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
27
votes
4answers
3k views

Are if else statement equivalent to logical and && or || and where should I prefer one over the other?

I'm learning about decision making structures and I came across these codes: if [ -f ./myfile ] then cat ./myfile else cat /home/user/myfile fi [ -f ./myfile ] && cat ./myfile || ...
14
votes
2answers
64k views

How to pass parameters to function in a bash script?

I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable ...
-3
votes
2answers
443 views

Using an shell glob (wildcard (*)) after a double quoted variable expansion

I read that it is a best practice to double quote all of your variable expansions in Bash. I also read that one cannot use a shell glob (wildcard(*)) right after a double quoted variable expansion. ...
48
votes
3answers
8k views

Is $() a subshell?

I understand the subshell syntax to be (<commands...>), is $() just a subshell that you can retrieve variable values from? Note: This applies to bash 4.4 based on different wording in their ...
2
votes
2answers
358 views

From multiline heredocument to a uniline herestring, with line breaks

I have this multilinie heredocument which I desire to translate into a uniline herestring: cat <<-"PHPCONF" > /etc/php/*/zz_overrides.ini [PHP] post_max_size = 200M upload_max_filesize ...
0
votes
2answers
96 views

Uunderstanding the redirections in this command? [duplicate]

I found a magic command here ./my.sh 3>all 1> >(tee out >&3) 2> >(tee err >&3) I am confused at some places: Does 3>all mean setting the file descriptor 3 for file ...
9
votes
2answers
462 views

Why does a brace command group need spaces after the opening brace in POSIX Shell Grammar?

TL;DR: Why does POSIX brace group need spaces after { reserved word but subshell doesn't after reserved word (? POSIX shell grammar defines brace group and subshell as follows brace_group : ...
6
votes
4answers
1k views

back ticks vs double quotes

I've been wondering this for a long time but haven't figured out how to look it up - is this: x=`command -v r2g` the same as this: x="$(command -v r2g)" or is it the same as this: x=$(command -...
5
votes
1answer
1k views

null string as command in while loop: empty/null-command

I'm wondering how the while loop evaluates its loop condition. In the man page it is written: while list-1; do list-2; done The while command continuously executes the list list-2 as long as ...
3
votes
1answer
541 views

Meaning of the double dash in options [closed]

I've read that all multi-character command options must be preceded by a double dash (--). But many flags for the find command (e.g. -name or -type) are preceded by only one dash. Why is that?
2
votes
1answer
156 views

Is it a best practice to use Ansible-Galaxy roles in playbooks instead ansible-modules in playbooks? [closed]

I have an Ansible playbook for establishing LAMP environments on remote machines. Part of this playbook deals with installing Composer: - name: Install Composer get_url: url: https://...
1
vote
2answers
66 views

How does '-' work in bash redirection?

I have seen this explained somewhere before but can't find a reference now. An example usage from docker getting started guide for Ubuntu: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | ...
1
vote
1answer
127 views

Hyphen (-) ignored in the end of a piped command nested inside a function?

I use Ubuntu 16.04 (xenial) with Bash 4.3.48(1). Based on the answer of Stephen Kitt in this session, I tried run the following command as part of a function named imb(): mysqldump -u root -p --all-...
0
votes
1answer
707 views

How does pushd work?

In Ubuntu 16.04 with Bash I had a problem when I didn't have a convenient way to upgrade all my WordPress components (core, translations, theme, plugin) and I used the following code to solve it: cat ...
-1
votes
2answers
225 views

Why not seeing shell globs as a “dialect” of regex? [duplicate]

I often confuse Bash 3.x shell globs: ? # Match any single character. * # Match any string of characters (up until the asterisk). [set] # Match any character in set (but not the entire set ...