Reputation
1,837
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
6 17
Newest
 Good Answer
Impact
~75k people reached

16h
awarded  Good Answer
Apr
1
comment How can I split a line in 2 by words/characters? (Bash) (Regex)
This and this. The main idea is that reserved variable names are in uppercase. If you use uppercase in your own variable names, you will one day have problems if you define PATH or HOME, etc. It actually happens very often that users define the variable PATH and then wonder why their script stops working all of a sudden. Latest to date is this one: stackoverflow.com/questions/29387616/…
Apr
1
comment How can I split a line in 2 by words/characters? (Bash) (Regex)
Good practice: 1. don't use uppercase variable names. 2. To get the number of characters in a string, use: chars=${#your_string}. Since you want half plus one: chars=$((${#your_string}/2+1)). This saves a subshell and a fork to external program (and saves from pathname expansion with your unquoted echo $YOUR_STRING). 3. Use more quotes: echo "$your_string" | fold -sw "$chars". Without the quotes for $your_string, you'll get surprises if your string contains glob characters like ?, *, [...] and extglobs constructs too if extglob is set.
Apr
1
comment How can I split a line in 2 by words/characters? (Bash) (Regex)
@user264974 the characters in the ranges A-Z and a-z are not wide characters, so it'll work fine with these.
Mar
31
comment How can I split a line in 2 by words/characters? (Bash) (Regex)
echo | wc is useless here. There are important quotes missing. This doesn't really show good practice. Also, be aware that fold counts bytes and not characters. So you will definitely get 3 lines or more if there are any wide characters.
Feb
26
revised What's the difference between shell builtin and shell keyword?
deleted 1 character in body
Feb
26
answered What's the difference between shell builtin and shell keyword?
Feb
24
awarded  command-line
Feb
2
comment How do I insert a line at the top of a text file using the command line?
@vp_arth If your content is in variable first_line then: ed -s filename < <(printf '%s\n' 1i "$first_line" . wq). Make sure that the variable doesn't expand to a single dot, and doesn't contain any newline characters (so sanitize it if it comes from user input).
Dec
2
awarded  Yearling
Nov
8
comment How to rename file extension to lowercase?
@KasiyA you know what? try it first on your own on a pendrive with a FAT32 partition. Then you'll see…
Nov
8
comment How to rename file extension to lowercase?
@KasiyA do you understand what are the same file means?
Nov
8
comment How to rename file extension to lowercase?
And to get the error are the same file, do: touch gniourf; mv gniourf Gniourf.
Nov
8
comment How to rename file extension to lowercase?
Very likely, OP is on a case-insensitive filesystem (as was already mentioned in several comments). As an example, try it yourself on a pendrive with a FAT32 partition ;).
Nov
8
comment How to rename file extension to lowercase?
Where's the contradiction?
Nov
8
comment How to rename file extension to lowercase?
Did you read that the question mentions the following error? mv: ‘P1010521.JPG’ and ‘P1010521.jpg’ are the same file. Are the same file…
Oct
29
revised How do I insert a line at the top of a text file using the command line?
typo: forgot the \n in printf
Sep
30
awarded  Explainer
Sep
21
awarded  Custodian
Aug
13
awarded  Good Answer