Questions tagged [whitespace]

combination of spaces, tabs, or newlines which create "empty" space in a line or column

Whitespace, or white space, is often used to refer to any combination of spaces, tabs, and new lines which create blank (or white, originally referring to the background color behind it) space between text, either horizontally or vertically.

When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page.

Useful links:

Whitespace character

Unicode information.

159 questions
370
votes
6 answers

Why does my shell script choke on whitespace or other special characters?

… or an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names). I encountered a problem such as the…
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
361
votes
21 answers

How do I trim leading and trailing whitespace from each line of some output?

I would like to remove all leading and trailing spaces and tabs from each line in an output. Is there a simple tool like trim I could pipe my output into? Example file: test space at back test space at front TAB at end TAB at front sequence…
rubo77
  • 27,777
  • 43
  • 130
  • 199
148
votes
6 answers

Why does Vim indent pasted code incorrectly?

In Vim, if I paste this script: #!/bin/sh VAR=1 while ((VAR < 10)) do echo "VAR1 is now $VAR" ((VAR = VAR +2)) done echo "finish" I get these strange results: #!/bin/sh #VAR=1 #while ((VAR < 10)) # do # …
elbarna
  • 12,050
  • 22
  • 92
  • 170
78
votes
2 answers

Why is bash not storing commands that start with spaces?

If I perform a sequence of commands like: $ ls $ grep abc file.txt and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here) But if I do something like this: $ ls $ grep abc…
sandyp
  • 1,117
  • 2
  • 8
  • 11
51
votes
3 answers

Removing all spaces, tabs, newlines, etc from a variable?

This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel). I am getting spaces in that variable. + 0 != 2 ./setjobs[19]: 0: not found. How do I…
munish
  • 7,825
  • 24
  • 71
  • 97
33
votes
3 answers

How to automatically strip trailing spaces on save in Vi and Vim?

Is there a .vimrc setting to automatically remove trailing whitespace when saving a file? Ideally (to be safe) I would like to only have this functionality for certain files, e.g. *.rb
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
31
votes
1 answer

Ignore whitespaces changes in all git commands

I've found tons of sites that explain how to have git warn you when you're changing line endings, or miscellaneous other techniques to prevent you from messing up an entire file. Assume it's too late for that -- the tree already has commits that…
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
20
votes
2 answers

Brackets in if condition: why am I getting syntax errors without whitespace?

I am using the below script to move two days back when script runs at starting two days of the year and also check first and second days of every month and move two days back. if [$month="01"] && [$day="01"]; then …
Kumar1
  • 341
  • 2
  • 3
  • 5
17
votes
2 answers

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX compliant way of working with lists of filenames…
Eero Aaltonen
  • 621
  • 1
  • 5
  • 13
15
votes
5 answers

How to make xargs handle spaces and special characters?

I have a file that contains a list of names. i.e.: Long Name One (001) Long Name Two (201) Long Name Three (123) ... with spaces and some special characters. I wanted to make directories out of these names, i.e.: cat file | xargs -l1 mkdir It…
Majal
  • 252
  • 1
  • 2
  • 9
15
votes
3 answers

Why does bash have a HISTCONTROL=ignorespace option?

Or to phrase it differently, why would you want to prevent commands from being written to the bash history? (Inspired by a related question.)
LoicAG
  • 273
  • 2
  • 8
14
votes
2 answers

Quoted vs unquoted string expansion

for i in $(xrandr); do echo "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done I understand why 1 differs from 2. But why does 3 give a different output from 2? Please explain the output too. How do quotes…
ManuelSchneid3r
  • 4,256
  • 8
  • 41
  • 58
14
votes
2 answers

Why are bash tests so picky about whitespace?

As a primarily Java programmer, I find the bash if-then construct quite confusing, especially regarding whitespace. Can anyone explain why the first one works, but not the second or third? #works if [ -n $1 ]; then echo "parameterized"; fi #output:…
Konrad Höffner
  • 996
  • 1
  • 16
  • 26
13
votes
1 answer

Posix Character Sets difference between [[:blank:]] and [[:space:]]?

On this website it says: [[:blank:]] space and tab characters [[:space:]] whitespace characters What's the difference between space and tab characters and whitespace characters? To me, they almost seem the same.
14wml
  • 243
  • 3
  • 6
12
votes
3 answers

What difference does it make matching a word with/without a trailing whitespace?

I am learning shell-scripting and for that I am using HackerRank. There is a question related to sed on the same site: 'Sed' command #1: For each line in a given input file, transform the first occurrence of the word 'the' with 'this'. The search…
JHA
  • 127
  • 1
  • 5
1
2 3
10 11