Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 42620

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.). Check scripts with https://shellcheck.net before posting.

0 votes

Unix Shell program to detect which half of month is it. Day of month (dom) -le 16

dd=$(date +%d) # values 08 and 09 will not work with arithmetic the way you expect d=${dd#0} # remove any leading 0 if [ "$d" -ge 16 ] ;then half=16 else half=01 fi date "+%Y%m$half" I t …
jrw32982's user avatar
  • 1,099
1 vote

Shortest way to extract last 3 characters of base (minus suffix) filename

If perl is available, I find it can be more readable than other solutions, specifically because its regex language is more expressive and it has the /x modifier, which allows for writing clearer regex …
jrw32982's user avatar
  • 1,099
0 votes

Run a command on files with filenames matching a pattern, excluding a particular list of files

Although I'm impressed by the reduced linecount and improved efficiency of other answers, I'd like to offer a different approach which prioritizes simplicity of code. This approach will make your fut …
jrw32982's user avatar
  • 1,099
14 votes
1 answer
3k views

Why does cd '' succeed in bash?

Maybe I'm missing it, but I don't find it documented that cd '' should succeed. Since there is no directory with the name '', it seems obvious that it should fail. For example, mydir= cd -- "$mydir" …
jrw32982's user avatar
  • 1,099
3 votes

Possible to match multiple conditions in one case statement?

Another choice: use functions. $ cat tt #!/bin/bash mon() { echo " Mon" ; } tue_fri() { echo " Tue|Wed|Thu|Fri" ; } fri_sun() { echo " Fri|Sat|Sun" ; } now=$(date +"%a") [[ …
jrw32982's user avatar
  • 1,099
0 votes

UNIX command to add comma and space

Some more simple variations: cat IP | sed 's/$/, /' | tr -d '\n' | sed 's/, $/\n/' or cat IP | perl -pe 's/\n/, /' | perl -pe 's/, $/\n/'
jrw32982's user avatar
  • 1,099
3 votes

parse one field from an JSON array into bash array

To handle arbitrary values: #!/bin/bash cat <<EOF >json [ { "item1": "value1", "item2": " val'\"ue2 ", "sub items": [ { "subitem": "subvalue" } ] }, { " …
jrw32982's user avatar
  • 1,099