The tag has no usage guidance, but it has a tag wiki.

learn more… | top users | synonyms

1
vote
1answer
35 views

How can I edit my bash script to account for whitespace entries? [duplicate]

I made a script to automate ffmpeg conversion from mkv > m4v > open the m4v in Subler.app to import the metadata manually, at which point I'll move the file into my iTunes library. I use iTunes ...
2
votes
1answer
44 views

Change to a directory containing a space

I'm using a MacBook with OS X installed. I'm on Terminal trying to go to a directory. So I'm in Home and I use the command ls and there is a VirtualBox VMs directory. But when I try to do cd ...
1
vote
1answer
200 views

Octals 302 240 together seem to correspond to non-breaking space

By looking at a particular line of a text file (say, the 1123th, see below), it seems that there is a non-breaking space, but I am not sure: $ cat myfile.csv | sed -n 1123p | cut -f2 Lisztes feher $ ...
1
vote
0answers
19 views

Creating command from some of the arguments to a bash script including whitespaces [duplicate]

I have a bash script that takes some arguments and uses some of them to loop over some action while some others (those of the form 'a=b') are passed to that action. Essentially, it looks like args= ...
1
vote
2answers
50 views

How to allow spaces in directories when using find -exec together with basename?

I'm trying to find all the directories in a given path, and create soft links inside those directories into directories with the same names at another location. Many of the directories have spaces in ...
4
votes
3answers
146 views

How to make xargs handle spaces and special chars from cat?

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 ...
2
votes
1answer
98 views

Error when substituting part of curl command with variable

I'm writing a script where I am running curl commands several times. The use of the curl command varies throughout the script and I would like to save myself time (in the future when I have to debug ...
2
votes
3answers
179 views

Process a file list with space in file names [duplicate]

I am trying develop a bash script which processes a list of files which may contain space names. (I have already consulted Trouble in script with spaces in filename and Why I can't escape spaces ...
1
vote
1answer
65 views

bash error on eval containing blank space

I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this: ./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' On ...
1
vote
1answer
43 views

Are configuration files usually sensitive to trailing whitespace

I was trying to configure LightDM. It appears that lightdm.conf is sensitive to trailing spaces. I found that I get different behavior with greeter-hide-users=true and greeter-hide-users=true ...
0
votes
1answer
73 views

Expand parameter in quotes in zsh

(Not sure the title is adequate, at least I tried my best…) I want to pass function arguments to zsh’s emulate to evaluate a command in bash emulation: $ .bash() { emulate bash -c "$*" } $ .bash ...
1
vote
1answer
117 views

Pass list of directories (that contain whitespaces) to a command in a script

For example, I want to execute the following within a shell script: tar cvpzf /destination/backup.tgz /directory\ one /directory\ two I wish to assign the list of paths (with whitespaces in them) ...
2
votes
3answers
544 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 ...
3
votes
2answers
320 views

How can I count the number of whitespace characters in a file?

I wanted to count the number of whitespace characters in a file. The best I could come up with was: tr -cd [:space:] < my_file | wc Is there a neater way?
1
vote
1answer
162 views

bash: Passing several space containing filenames

In a bash script I am rasterizing a PDF page by page into single files, in the end the single resulting PNGs are merged again into a PDF like this: convert -monitor /path/to/1.png /path/to/2.png ...
5
votes
10answers
685 views

How to quickly add some space in the terminal?

I often find myself scrolling back through the terminal with the mouse-wheel to see the first of many C++ template errors issued by a command. Anticipating this, I'll hold down the Return key to give ...
45
votes
3answers
6k 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: ...
2
votes
1answer
178 views

Indented here document causes a syntax error

I have the following code fragment in my shell script and have a bug that I can't seem to pin down a reason for despite some research. When I run the code as below the script exits with a message ...
2
votes
2answers
648 views

How to handle spaces in path names when variable contains multiple paths [duplicate]

Although I've read myself through most of the questions about handling spaces in path names, I haven't found my case yet, which is about several path names in one variable. find will need this when ...
1
vote
1answer
3k views

Bash script: array elements containing space character [duplicate]

I'm getting started with bash scripting. I'm working with array elements that contain space characters. In the code below, the third array element is "Accessory Engine". I tried to set the space ...
1
vote
1answer
192 views

Why doesn't my function work with spaces? (cd, dirname) [duplicate]

I have had this function I use it very often and it works fine. Here it is: cdx () { cd `dirname $1` ; } However, this does not work with spaces. When I use it like this for example cdx ...
1
vote
6answers
1k views

How do I deal with directories that have spaces in their names from `find`? [duplicate]

I have this: #!/bin/bash for file in `find . -type d` do echo $file done If I have just one directory called My Directory, the output is My Directory How do I fix this? The echo $file is ...
2
votes
3answers
381 views

How to sort filenames with spaces in them and concatenate the files?

I have the misfortune of dealing with filenames that contain spaces. I want to concatenate files of which filenames contain spaces. I also want to sort the filenames numerically. Obviously the ...
0
votes
0answers
19 views

Print the page count within the PDFs in a directory to a output txt file [duplicate]

The need has been to identify the total page count of all the PDF files we have in a repository. For that, I was able to come up with the following script. However, I'm now stuck with this situation: ...
1
vote
1answer
595 views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f ...
1
vote
2answers
164 views

bash question about if and then [duplicate]

I'm writing this in my script. It has other parts but I'm getting stuck on this part only. if [[$# == $year $month $day ]] ; then cal $day $month $year fi When I run this it give me this msg: ...
3
votes
1answer
1k views

Storing whitespace in a shell script variable [duplicate]

I need to store specific number of spaces in a variable. I have tried this: i=0 result="" space() { n=$1 i=0 while [[ "$i" != $n ]] do result="$result " ((i+=1)) ...
3
votes
3answers
1k views

What perl script will scp directory with spaces in name?

I"ve been trying for several hours to figure out how to get perl to scp a directory with a space in the name. I'm currently getting the error scp: ambiguous target Here is the script that is not ...
4
votes
1answer
2k views

Rename files with spaces in a BusyBox shell

I'm trying to rename some files on my Synology Diskstation via SSH. The available shell is the BusyBox built-in shell: BusyBox v1.16.1 (2013-04-16 20:13:10 CST) built-in shell (ash) The move ...
3
votes
3answers
1k 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"] ...
2
votes
1answer
384 views

csplit not obeying backslash r \r as carriage return

I have a file with \r\n line endings (CRLF carriage return line feed). This command works: $ csplit --silent --prefix=email-emailbad.txt- \ --digits=3 emailbad.txt '/^\.^M/'+1 '{*}' This ...
92
votes
3answers
54k 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 ...
0
votes
1answer
68 views

Why does vim jump down to same position after multiple spaces?

I really can't find the answer to this and I would like to understand what going on behind the scenes to make this happen. Is it a setting I have switched on? If so, which one? To give an example, I ...
2
votes
2answers
3k views

How to add a string with spaces at the end of command output

I want to add a string with spaces at the end of each line of the output of ls command. #!/bin/sh STRING_WITH_SPACES="this should be at the end of output" ls -lh | sed 's|$| '$STRING_WITH_SPACES'|' ...
1
vote
2answers
455 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 ...
8
votes
3answers
2k 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.)
20
votes
1answer
1k 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 ...
1
vote
1answer
967 views

Sed: search and replace a patten with special characters which has a arbitrary string in between

I have a load of nfo files which I want to make some global substitutions for some values within each file e.g. a.nfo has the value <set>Tonight&apos;s Menu ( June 2012 )</set> ...
4
votes
1answer
284 views

Trailing spaces when copying from gnome-terminal using zsh

When copying text from gnome-terminal with zsh trailing whitespace is also copied. For example copying the following clearly adds a vertical scollbar on stackexchange site as trailing whitespace the ...
2
votes
3answers
4k views

How to identify and remove invisible whitespace characters on gedit?

I want to remove unnecessary whitespace on my css file. I am using grep with the command as follows: $ grep -rn "[[:space:]]$" Surprisingly, it is returning a hit on every line in the file. I ...
3
votes
1answer
852 views

terminal command that prints out tabs, spaces, and newlines as \t \s and \n

I wrote a terminal program in c that converts tabs to spaces. And I would like to see that it works and how many spaces were converted from tabs. The problem is when I create a file called input.txt ...
10
votes
3answers
1k 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 ...
26
votes
7answers
30k views

how do I trim each line in bash?

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?
1
vote
1answer
71 views

Emacs - Strange Whitespace

(I posted this same general question here on StackOverflow thinking it had something to do with my emacs configuration, but after following a comment there, I think it is exclusive to urxvt) My ...
6
votes
2answers
1k 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 ...
0
votes
1answer
352 views

Unexpected whitespace using sqsh in command substitution [closed]

Below shell script instruction behave in weird way ARG_DATE=`sqsh -S $SERVER -U $DB_USER -P $DB_PASSWORD -D dbname -h<<END SET NOCOUNT ON go select convert(varchar, PRIOR_COB_DATE, 112) from ...
6
votes
2answers
459 views

Bash commands with spaces in them (git config or git-config?)

Please forgive me if this seems easy, but I only started learning Unix 2 days ago. Basically, I have been taught that when typing a command into the terminal it needs to be of the form: [command ...
18
votes
3answers
8k 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
0
votes
2answers
3k views

what is “an invisible whitespace character that takes up space”

One can look up Unicode Characters with Regular Expressions. On Jan Goyvaerts website I found a RegExp whose meaning I don't understand : \p{Zs} or \p{Space_Separator}: a whitespace character that ...
3
votes
2answers
403 views

Generic Preprocessor adds extra whitespace

Following up on this article I use GPP to empower Markdown parser pandoc with some macros. Unfortunately, gpp seems to copy all whitespace into the result. For example, consider file test.md % Title ...