Hot answers tagged

10 votes
Accepted

How to create multiple files (with different names) in a specific directory all at once in a Linux terminal

Yes, you can create multiple files with different names in a single command using terminal. Here's an example command that does exactly what you want: mkdir -p src/components && touch src/...
  • 276
3 votes

bash: syntax error near unexpected token '|'

The syntax error you're receiving is because the regular expression needs to be surrounded by quotes, either single or double. Otherwise, the vertical bar character is treated as a Unix pipe, which ...
  • 53
3 votes

bash: syntax error near unexpected token '|'

In almost all cases, it is necessary to mask your regex to prevent the shell from interpreting it and handing an already (partly) interpreted version to find. find ./ -regextype posix-extended -regex &...
  • 6,222
3 votes

Sound works as root but no sound as www-data

The user www-data is by default a member of only the www-data group for security reasons. Only, members of the audio group can play audio. You can test by adding the www-data user to the audio group ...
  • 20.3k
3 votes

Passing multiple file patterns to grep

How about giving the patterns to grep through a sub-shell, e.g.: grep -f <(printf "%s\n" "${ptrn[@]}") FILE...
  • 3,438
2 votes

Passing multiple file patterns to grep

If your patterns/words stored as array elements are guaranteed to not have spaces or non-escaped shell special characters in them, then you can use bash's parameter expansion to pass the array ...
  • 20.3k
2 votes
Accepted

Bash function processing on arrays

This seems like a typical XY problem question ... So, all I can do to help is to highlight some points you mentioned and hopefully this will at least help you avoid dead ends and point you away from ...
  • 20.3k
2 votes
Accepted

Passing multiple file patterns to grep

Two options: Standards-compliant way: Join the patterns with newline and provide it as single argument: grep -e "$(printf "%s\n" "${ptrn[@]}")" ... (This feature is ...
  • 190k
1 vote
Accepted

reading multiline output of command into variable in bash script

You're not quoting the variable. echo "$disk_info" The variable contains all the newlines, but the shell expands the value to parameters to echo. Double quoting the variable prevents the ...
  • 9,128
1 vote
Accepted

Running grep via GNU parallel

grep is one of the most refined and time proven tools performance-wise ... Please, see for example the speed comparison of grep with other text-processing tools on very large 1G+ files with 8M+ lines ...
  • 20.3k
1 vote

How to create a rotation animation using shell script?

very minimal way of writing using printf sh-5.1$ while true ; do for i in \\ "|" / "-"; do printf "$i" ; sleep 0.1 ; printf "\b" ; done ; done

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