Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.

learn more… | top users | synonyms

7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
4
votes
2answers
39 views

Store quotes in variable to use as command line parameter Bash

I am writing a script to call a command (weka, if you are curious) a couple of times with some different parameters. One of the parameters, '-search "< stuff >" ' needs to be quoted. In some ...
0
votes
1answer
59 views

grep with variable in a variable

I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this ...
1
vote
1answer
35 views

Rewrite a find command that uses sed -i for AIX

I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current ...
1
vote
2answers
45 views

Shell eating `?` characters

This is such a simple question that I'm sure it's been asked somewhere, but I can't find it. My shell, which I have not intentionally set up to do so, seems to eat any words involving question marks: ...
0
votes
0answers
31 views

Why do konsole expand $VAR inside single quotes in <-e> command line option?

I want to print a string and be sure all $VARs inside it are not expanded to their values. That's why I enclose my text in single quotes. Example: echo '$SHELL';read -sn 1 This command displays ...
0
votes
0answers
12 views

Bash script not passing variable through ssh [duplicate]

I'm trying to write a script that will ssh into multiple servers and echo the line user_pref("plugin.state.java",2) into every user's firefox pref.js file. I keep getting the error bash: ...
1
vote
2answers
46 views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
1
vote
0answers
22 views

Passing external parameter to .exe on Windows using winexe from Linux

I am trying to execute a .exe on Windows from Linux using winexe. This exe requires an external parameter (string) to be fed alongwith. With the following command I have succeeded in initialising the ...
2
votes
4answers
631 views

Why does the grep command ignore the period in the search string?

The command that I am using: find . -type f -name "*.sql" -exec grep -i -l 'schema_name.' {} + What I want to search is all the files which contain schema_name.. But the find command is ignoring ...
1
vote
2answers
85 views

Escaping in bash

Given a text message, I need to programmatically generate a bash command to open terminal emulator and show this text in it. For example, for HelloWorld input string I need to return the following ...
1
vote
1answer
68 views

regular expression : with a variable

arrFormat=( jpg jpeg bmp tiff png ) varExtension="jpg" for elem in "${arrFormat[@]}" do   echo "${elem}"   # do something on $elem # done #for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do ...
0
votes
1answer
63 views

How do I accept input string in bash without losing the quotes?

Example, I have this function in my .profile: alias () { command alias "$@" } However, this executes: $ alias test=ls if I run $ alias test="ls" How can I make it accept the string with ...
16
votes
1answer
1k views

Why does this ffmpeg command work in bash and not zsh?

Today I got home from work (run bash on an Ubuntu box) and tried to run some code on my local arch box with my beloved zsh and the commands were failing? The command is below with the personal info ...
1
vote
2answers
62 views

Why some commands don't load user environment when executed with ssh? (while other do)

On a target machine (OS X El Capitan) I have brew in /usr/local/bin. When I try to get brew's path I get no result: # ssh vagrant@127.0.0.1 -p 2222 which brew # Troubleshooting: brew is in ...
3
votes
1answer
243 views

What characters are required to be escaped in command line arguments?

In Bash, when specifying command line arguments to a command, what characters are required to be escaped? Are they limited to the metacharacters of Bash: space, tab, ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ...
1
vote
4answers
52 views

Why does read with pipeline fail in an ssh session?

Why does this show blank lines instead of folders found by find? ssh -o stricthostkeychecking=no -o userknownhostsfile=/dev/null \ -o batchmode=yes -o passwordauthentication=no user@myserver.xx \ ...
0
votes
2answers
34 views

bash script function argument problem [duplicate]

Not sure why this is producing error. This is a test code emulating my real code. I want to write a wrapper for find and want to allow for any argument, so I'm wrapping each arg in single quotes. ...
7
votes
1answer
578 views

What does `\time`, `t\ime` and `\cd` actually do? (fun with backslashes in shells)

While discussing over the differences between /usr/bin/time and the shell (bash and zsh) built-in time, someone mentioned that one can use \time as a shorthand to get /usr/bin/time. First it seemed ...
3
votes
2answers
386 views

Printf printing only a single line

I'm trying to get the output of env in a shell variable and print it. #!/bin/sh ENV_BEFORE=$(env) printf $ENV_BEFORE As a result a single variable from the env output gets printed. When using echo ...
1
vote
0answers
35 views

Copy file into all subdirectories that contains a file with certain name

I am trying to copy a features[30,55].R script from my desktop into all the subdirectories that contain a file whose name is DONE. I tried the following command: find . -name "DONE" -exec sh 'cp ...
1
vote
1answer
25 views

Manual pages uses the quotation : `<character/string>' (quoting string inside grave accent and apostrophe) [duplicate]

I've found that many manpages uses the quotation :  `c/s' i.e quoting character or sting inside grave accent(`) & apostophe('). Example visit manpage of bash, find etc. and you'll find the ...
1
vote
2answers
69 views

Using special character " and ` in send command in expect script

I am trying to execute a command in Linux servers to fetch which all servers requires root password reset as there are multiple servers I am using an expect script to automate it , my command contains ...
3
votes
2answers
160 views

Why the defined path is used as file name when I transfer files through scp to a Windows host?

When trying to copy a file from Linux (Raspbian to be precise, though I don't think it matters) to Windows using SCP: scp a.txt {user}@{ip}:\C\Users\{user}\a.txt The file is copied, but to ...
3
votes
2answers
58 views

Passing a list of two PIDs to xargs only kills the first using ssh

I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9 Both processes are killed when executing ...
3
votes
1answer
54 views

On passing arguments to programs through array variables

NB: though the question below features rsync, it is not a question about rsync; it is a question about zsh arrays. If I initialize the variable EXCLUDES like this EXCLUDES=( --exclude=/foo ...
1
vote
2answers
73 views

find “corrupt” file, nesting an if inside a find command

I'm trying to find "corrupt" files inside a directory structure, namely files which the file command would interpret as "data". Here is the command I've been trying to run, but fails: $ find . -type ...
3
votes
3answers
158 views

cannot move file because of & in name

Trying to command mv foo&foo.jpg images/ but get command not found, then if try and rename the file it won't let me.
1
vote
1answer
63 views

bash adds apostrophes to expanded variable

I am reading in a file inside my bash script where each line consists of multiple columns like this: ANSIBLE 'first run' '--diff --extra-vars "client=yes fast=no"' As you can see, the line consists ...
0
votes
2answers
47 views

Define string with the characters *, single quote and $

I create bash scripts which get sourced from another "main" script to set up variables needed by the main script. These variables need to be able to contain any character and not have them interpreted ...
3
votes
4answers
54 views

Bash converting path names for sed so they escape

I'm having a problem with a script. It is meant to change a value in a file called %DIR% so that it becomes a path name. The problem is the slashes in the directory name upset sed, so I get weird ...
1
vote
1answer
63 views

How to escape a range of wildcards in unix shell script?

I need to execute the following Oracle SQL in unix crontab. The query is as follows: select count(*) from tbaadm.htd where cust_id is not null and pstd_flg = 'Y' and del_flg = 'N' and tran_date = ...
0
votes
2answers
86 views

Bash syntax error when `cd`ing into directory

**So, after doing a little digging, I got it to work. You do get far enough in the install using WINE for this to work properly. Here are the steps: Open the shell, and type in cd .wine ...
1
vote
1answer
41 views

Nested strings in bash command [duplicate]

I am attempting to write a script to list all the shebang lines in python files. What I would like to do is sudo bash -c 'for logf in $(find / -name "*.py"); do fgrep '#!/usr/bin' "$logf"; done' ...
4
votes
2answers
85 views

confusing about double quoting

I learned when I use command, double quoting treat all things as character except $, `, \ . But, when use command like find -type f -name "*.jpg" *.jpg is inside double quotes. Then, it means we want ...
3
votes
1answer
26 views

Globbing error due to whitespace

My directory variable POSTMAP="/work/Documents/Projects/untitled\ folder/untitled\ folder/*/*_tsta.bam" My for statement: for file0 in ${POSTMAP}; do ... It seems that the whitespace in ...
0
votes
1answer
44 views

Unable to move files having spaces in their name [duplicate]

I want to move files from one folder to another folder, my code is working fine when file name doesn't contain spaces but if there is a space in a file name then I am getting an error My Code is as ...
2
votes
1answer
52 views

Why are these nested options in a POSIX shell script being word-split?

I have a script count_args that counts arguments: #!/bin/sh echo $# If I call it with these options, it tells me it gets two arguments: $ ./count_args --options '1 2' 2 But if I construct the ...
3
votes
4answers
207 views

How to escape shell metacharacters automatically with `find` command?

I've got a bunch of XML files under a directory tree which I would like to move to corresponding folders with the same name within that same directory tree. Here is sample structure (in shell): ...
45
votes
4answers
2k views

Why is 'ls' suddenly wrapping items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them ...
0
votes
2answers
88 views

Echo a string with a variable in it without expanding/evaluating it [closed]

I've searched everywhere. Tried echo and print. Tried single and double quotes. But I have parsed data and assigned it to a variable and would like to then evaluate it for if there is a variable ...
3
votes
2answers
192 views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, i.e. read -d '' <variable> script block ...
0
votes
0answers
32 views

Is it possible to ssh and execute a remote command with a single quote in it? [duplicate]

ssh user@host "mv \"/some/path/fi\'le.txt\" /some/new/path" It doesn't matter what I do, or what combination of quotes I use on the file, it gives the following: bash: -c: line 0: unexpected EOF ...
5
votes
2answers
69 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
1
vote
1answer
39 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
5
votes
2answers
118 views

How to insert newlines into PATTERN when using fgrep / grep -F / grep --fixed-strings

When using fgrep, the man page says it will Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. In bash, what's the correct way to insert ...
0
votes
2answers
31 views

Bash script doesn't convert variables [duplicate]

I was attempting to create a bash script to run a backup of my Raspberry Pi to my Box account via FTP. Most of it works, but for some reason it won't convert variables to the text they stand for. When ...
0
votes
1answer
43 views

Parenthesis on echo shell command

I have this echo command: $ echo "alias notepad++="C:/Program\ Files\ "(x86)"/Notepad++/Notepad++.exe"" >> ~/.bashrc As shown in the picture it does not recognize the parenthesis.
1
vote
2answers
112 views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
0
votes
0answers
16 views

Bash variable containing JSON splits on single quotes [duplicate]

(Apologies for the poor title, I'm not sure what the exact cause of my problem is which makes it hard to describe, I just know I can't get it to work.) I have a variable which contains JSON. I'm ...