Tag Info

New answers tagged

0

Isn't there some way to protect spaces in backtick (or $(...)) expansion? No, there isn't. Why is that? Bash has no way of knowing what should be protected and what shouldn't. There are no arrays in the unix file/pipe. It's just a byte stream. The command inside the `` or $() outputs a stream, which bash swallows and treats as a single string. As ...


8

Man pages are written in the troff/nroff markup language. Troff, which is meant for preparing output to a phototypesetter (or to files in formats such as PostScript or PDF), will automatically change the ` and ' characters in the input into curved quotation marks, ‘ and ’. Nroff, which is what the man command runs when the output is to a terminal, will pass ...


5

These quotation marks are often used because they look nice, similar to the quotation marks in printed books (which are different at the beginning and end of the quoted passage). These quotation marks may also have been added by your local troff configuration (or, could be removed by it!). The actual file may not contain these characters literally. You ...


4

The Theory The rules are : inside a ' delimited string, nothing gets interpreted and anything but a ' doesn't have special meaning. This means that only a ' need escaping but it also mean that, in order to escape it, you need the '\'' construct. (The first ' ends the string, the following \' adds a literal ' (the escape prevents the start of a new string) ...


1

At least with GNU sed: sed -i.bak '$a gem \x27forum2discourse\x27' file


4

sed -i '$a gem '"'"'forum2discourse'"'" Gemfile Alternate Solution If you wish to do it your way, then use the bash $'string' format. Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. sed -i $'$a gem \'forum2discourse\'' Gemfile Source: ...


0

sed -i -e '$a gem '"'"'forum2discourse'"'" yourfile


8

Inside [...], backslash is not special. [\[] matches both backslash and [1. If you want to include the ] character in the set, you have to make sure it's first: []X] matches ] or X while [X]] would match X followed by ] (and [X\]] would match X or \ followed by ]). To exclude it, it has to be right after ^: [^]X] is any character but ] or X. So, in your ...


1

your first example: { echo -e "foo\nbar" | sed -nre '/foo/! p' echo -e "foo\nbar" | sed -nre '/foo/!p'; } could be reduced to echo '! p' echo '!p' Within single quotes, all characters preserve their literal values. Thus ! has lost its special meaning and history expansion is not preformed. your second and third examples: var="$(echo -e ...


0

The wildcards in your regular expressions are expanded by the shell. The shell treats them as filename metacharacters. So, you have to tell the shell to not evaluate them as filename metacharacters and you do that by quoting them using single quotes, double quotes, or backslash character just before the metacharacter. Then, the shell sends the expression ...


3

As far as your patterns are concerned, this would be the safest to match only intended strings: grep 'AB.\{0,1\}-DEF' file.txt Or grep -E 'AB.?-DEF' file.txt . matches any single character, ? and \{0,1\} matches the previous token zero or one time, so in total .? and .\{0,1\}will match zero or one character before -DEF. If you use AB.*-DEF or AB.*DEF, ...


1

You can use: grep 'AB.*-DEF' file.txt


8

* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF . in regex means "any character" so you could fix your pattern by using grep 'AB.*DEF'


2

Welcome to Linux! A trick that will get you started here (and will save you from getting carpal tunnel in the future) is "tab completion": $ ls /med then press Tab to see $ ls /media/ If you press Tab again, you might see a list of possible options to continue the path, $ ls /media/ MyBigExternalDrive/ My Example Hard Drive/ or (if there is only ...


4

An alternative to Eric's good answer: Tcl can do glob expansion expect <<'END_EXPECT' set timeout -1 # use this instead of sleep set files [glob -nocomplain ~/partFiles/*] if {[llength $files]} { spawn scp -C -o CompressionLevel=9 {*}$files abc@10.200.4.15:/export/home/abc/ expect password send ...


4

I think the ~ and * are expanded by the shell, but I bet expect invokes scp directly, bypassing the shell so those don't get expanded. You could try spawning sh -c the scp command. If it's an option, it might also just be easier to share your key with the server though so you don't need expect for this at all. Using the sh technique the command will end ...


1

Here are a couple of approaches (well, 2½): If you’re interested in being able to incrementally modify PS1 settings that follow a general template, Create a file that contains only the PS1=… line. Write sed commands to edit it, piece by piece; e.g., sed -e 's/${debian_chroot:+($debian_chroot)}/\\d \\t /' sed -e 's/\\033/\\e/g' etc. You might find it ...


1

ssh localhosts 'printf "`uname -n` `uptime| awk -F " " {'\''print $3,$4'\''}`\n"' The issue is that you had nested single quotes. That does not work well.


1

Using xargs, it can be done in this way: find . -type f -print0 | xargs -0 file | grep -v 'image' But xargs is so yesterday. The cool kids use parallel today. Using parallel, it would be: find . -type f | parallel file | grep -v 'image' See. No use of -print0 and -0. parallel is really smart by itself. UPDATE For listing only the most recent 500 ...


1

For generic advice regarding processing of file names potentially containing spaces, see Why does my shell script choke on whitespace or other special characters? The difficulty with what you're trying to do is that there's no nice way to list the N most recent files with standard tools. The easiest way to do what you're doing here is to use zsh as your ...


1

Is it possible that earlier you placed quotes around expr parameters, like this: $ expr '(-105.5*7+50*3)/20 + (19^2)/7' | bc -l 22.14642857142857142857 ? In this case expr doesn't perform any arithmetic operations and just prints the original expression: $ expr '(-105.5*7+50*3)/20 + (19^2)/7' (-105.5*7+50*3)/20 + (19^2)/7 All calculations ...


1

Use "find" with "-print0" option & pipe the output to "xargs" with "-0" option. Even though I know (and use) this technique, I see that user @Jens has answered a similar question, where you can find more Details : http://stackoverflow.com/questions/16758525/use-xargs-with-filenames-containing-whitespaces


-1

You might try printf "%s\0" $(ls -t | head -500) | xargs -0 file | grep -v image This forces xargs to null-delimit the file name arguments.


1

I have two crude suggestions that might help. Neither feels particularly satisfying though, so perhaps something better will come up. First, use sed to add quotes to everything, so you'd only end up with trouble if there are quotes in the file name like ls -t | head -500 | sed -e 's/\(.*\)/"\1"/' | xargs file | grep -v 'image' The other is to use the ls ...


1

The ; semicolon starts a comment that terminates your Git alias early hereby making it incomplete at the time Git tries to run the external shell command you aliased. The manual page of the git-config command states that a ; semicolon starts a comment that extends until the end of a line because Git configuration files are written in the INI format.



Top 50 recent answers are included