Questions tagged [whitespace]
combination of spaces, tabs, or newlines which create "empty" space in a line or column
167 questions
423
votes
22
answers
859k
views
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 ...
378
votes
6
answers
422k
views
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 ...
156
votes
6
answers
83k
views
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/...
85
votes
2
answers
28k
views
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 ...
55
votes
4
answers
146k
views
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 !=
...
34
votes
4
answers
24k
views
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
31
votes
1
answer
41k
views
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 ...
20
votes
2
answers
12k
views
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"...
17
votes
5
answers
32k
views
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 ...
17
votes
2
answers
7k
views
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 ...
15
votes
3
answers
10k
views
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.)
15
votes
7
answers
17k
views
Trailing spaces when copying from console
It's this annoying behavior I've been experiencing here and there occasionally: when you select text with mouse in console (that is, copy it), paste it, and realize you've got extra spaces at the end ...
14
votes
2
answers
10k
views
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 [...
14
votes
2
answers
8k
views
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 ...
13
votes
1
answer
10k
views
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 ...