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

learn more… | top users | synonyms

1
vote
2answers
80 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
159 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
73 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 ...
26
votes
2answers
8k views

How can I use column to delimit on tabs and not spaces?

I'd like to use Unix column to format some text. I have fields delimited by tabs, but within each field there are also spaces. column delimits on white space (tabs and spaces). How can I make column ...
95
votes
3answers
141k views

What characters do I need to escape when using sed in a sh script?

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
0
votes
2answers
48 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 ...
49
votes
4answers
3k 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 ...
3
votes
4answers
69 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
68 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
95 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
45 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
88 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 ...
0
votes
1answer
46 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 ...
28
votes
5answers
33k views

Parenthesis in bash arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
61
votes
3answers
11k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
3
votes
4answers
228 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): ...
5
votes
2answers
93 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: $ ...
2
votes
1answer
54 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 ...
20
votes
2answers
16k views

How are parentheses interpreted at the command line?

While reading up on how to set up grub, I came across an article claiming that I need to use one of the following two syntaxes, echo \(hd0,0\) >> /boot/grub/grub.conf or echo '(hd0,0)' ...
0
votes
2answers
315 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
0
votes
2answers
146 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
245 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
33 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 ...
1
vote
1answer
44 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
123 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
33 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
52 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
143 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 ...
38
votes
3answers
20k views

How can I execute `date` inside of a cron tab job?

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
0
votes
0answers
17 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 ...
1
vote
2answers
95 views

bash -c in subshell gives EOF parsing error

Why does the following script work as expected (prints hello) #!/bin/bash foo=$(bash -c 'echo hello') echo $foo while this script: #!/bin/bash cmd="bash -c 'echo hello'" foo=$($cmd) echo $foo ...
16
votes
6answers
579 views

Should variables be quoted when executed?

The general rule in shell scripting is that variables should always be quoted unless there is a compelling reason not to. For more details than you probably want to know, have a look at this great ...
3
votes
2answers
253 views

Passing paths with spaces as arguments

I am having difficulty in passing some string variables having spaces in them as arguments to a program. For debugging and showing the arguments being passed, I created a demo Python script -: ...
1
vote
1answer
53 views

Run for loop via ssh

Good day All, I'm attempting to run a for loop via SSH. The loop is used to get the last login of each user that has an account on the server, ssh 172.20.2.1 '''for i in `cat /etc/passwd | awk -F: ...
1
vote
1answer
55 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: ...
44
votes
3answers
16k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
0
votes
2answers
4k views

variables in find command and more shell problem [duplicate]

Possible Duplicate: Recursive rename files and directories I wrote the following script: #!/bin/bash SAVEIFS=$IFS alias export='export' IFS=$(echo -en "\n\b") find $1 -name "*" ...
2
votes
5answers
42 views

Help on edit a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
3
votes
2answers
154 views

Shell-independent escaping for strings in scripts

I just struggled (again) over this: # only in bash NORM=$'\033[0m' NORM=$'\e[0m' # only in dash NORM='\033[0m' # only in bash and busybox NORM=$(echo -en '\033[0m') The goal is to include special ...
2
votes
2answers
74 views

Exported variables inside ssh session are empty

I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo ...
2
votes
2answers
252 views

Passing multiple of arguments with whitespaces through a script to ssh

I want to remove multiple files from remote server. I have all files under one array in a script and I call other script which will remove files. Let output of "${b[@]}" is: ...
2
votes
1answer
38 views

quotes generated by another Bash script not treated like quotes inside original script [duplicate]

Using bash… my pwd contains directories with spaces: $ pwd /a/b c/d This works: $ ls "$PWD" bar foo # yay! It also works if I put that code inside a script. Now if I split that command in two: ...
5
votes
3answers
662 views

File name beginning with - (dash) [duplicate]

I have file called -l in my directory now I tried to do for i in *; do stat -c "%s %n" "$i"; done it lists all files with sizes but in the middle of the output there is something like 395 ...
0
votes
1answer
34 views

Script with variable in path

I'm not entirely sure where to ask or how to formulate this question with correct terminology. I have script here for managing a game (minecraft) server for the user (bukkit). I've cut out some ...
1
vote
2answers
285 views

Remove file with pound signs around it [duplicate]

I am using SSH to another terminal with very limited disk space. upon typing ls I see a file called #korpus.txt#. I suspect this file is an emacs buffer, but upon running emacs and trying to kill it ...
1
vote
1answer
85 views

How to declare some aliases dynamically in zsh?

I would like to declare a few shortcut commands to switch between my various coding projects, so I have come up with the following script. projects=$(ls -d ~/Workspace/*/) ...
1
vote
1answer
28 views

Why isn't this perl regex capturing the backreference?

I have a directory of files $ ls -1 ep2.mp4 ep3.mp4 ep4.mp4 ep5.mp4 ep6.mp4 ep7.mp4 I want to use the perl rename utility to make all files look like e.g. ep02.mp4 Command I am using rename -n ...
1
vote
1answer
84 views

Inserting variables in a command within a shell script

I'm attempting to write an automated script which will update the IP address for my Raspberry Pi within my /etc/hosts file. I'm able to execute this line just fine, IP=`sudo nmap -sP 10.61.4.0/24 | ...
0
votes
1answer
38 views

Escape shell arg from one script to another

Given ./mysh0: #!/bin/bash exec ./mysh1 $* And ./mysh1: #!/bin/bash echo $1 echo $2 echo $3 How do I call mysh0 such that the arguments to mysh1 and what's eventually printed are "A", "B 2" ...
2
votes
1answer
19 views

Parameter ignored when quoted

I have a directory with 3 files: file1, file2 and the following bash script: #!/bin/bash set -e Command="ls -1 -I file1" echo "Command: $Command" Files=`$Command` echo "Files:" echo $Files The ...