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
231 views

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

ssh has an annoying feature in that when you run: ssh user@host cmd and "here's" "one arg" Instead of running that cmd with its arguments on host, it concatenates that cmd and arguments with spaces ...
0
votes
3answers
25 views

Output to variable with an indirect command (eval)

What is wrong with this indirect command when run with eval ? #!/bin/bash OS=AIX host=myhost CMD_AIX="(o=\`host \"$host\" \`)" CMD=\$CMD_$OS echo $CMD eval echo $CMD eval "$CMD" Ouput: $ ...
4
votes
2answers
178 views

Man page quotation characters [duplicate]

I've just been looking through a few man pages for a few different commands including grep and ifconfig. I've noticed over a few pages, the content uses a strange syntax to notate what i think are ...
2
votes
1answer
43 views

How do I properly escape this long su + sed command?

#!/bin/bash wineuser=tom su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh" The acutal line inserted to tom's ...
0
votes
3answers
38 views

How can I add a line including single quotes to a file with sed [duplicate]

I want to append the following line to a text file with sed: gem 'forum2discourse' I've tried sed -i '$a gem \'forum2discourse\'' Gemfile but this drops me to a > prompt so I think I must be ...
6
votes
1answer
137 views

Why can't I escape the braces “]” in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
1
vote
4answers
216 views

Wildcards for filepaths aren't working in grep [duplicate]

I need to grep words like these: ABC-DEF AB2-DEF AB3-DEF AB-DEF So I was trying: grep AB*-DEF grep -w -AB*-DEF grep -w AB*DEF But neither of them are working. Please help.
2
votes
1answer
30 views

Can not access my external hard drive.

I am fairly new to Linux and have been trying to move some files around with terminal on my external hard drive but I can't seem to get it to work. I am using a generic external hard drive with a ext4 ...
5
votes
2answers
131 views

scp command behaves differently when used with expect utility

expect -c 'spawn scp -C -o CompressionLevel=9 ~/partFiles/* abc@10.200.4.15:/export/home/abc/; sleep 10; expect password; send "secretPassword\n";interact' throws - ~/partFiles/*: No such file or ...
1
vote
1answer
58 views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
0
votes
1answer
26 views

Syntax Error while running command from another hosts [duplicate]

I run a command to fetch server uptime as below [root@localhosts ~]# printf "`uname -n` `uptime| awk -F " " {'print $3,$4'}`\n" localhosts 75 days, Now when I run same command from another ...
3
votes
5answers
75 views

`xargs` with spaces in filenames

I'm trying to list only non-image files, searching only in the most recent 500 files. So I run ls -t | head -500 | file | grep -v 'image' which isn't right: it displays a help message. Changing it ...
2
votes
2answers
37 views

Git alias multi-commands with ; and &&

I want to have an alias that execute a command and then whether it fails or no it execute other commands that depends on the success of each other. So I have something like that in .gitconfig ...
0
votes
2answers
36 views

Exclude the output from ssh and only log the error if found

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} " $(cat); IFERROR=$(checkscript); echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1 This line...I can't exclude the ...
2
votes
1answer
23 views

Quoting: loop over ssh-accounts, call psql on remote server

This works in the human brain, but the shell misses quoting: for h in a b; do ssh $h psql -tAc "select * from mytab where mycol='x'"; done How to quote this one liner without loosing readability?
2
votes
1answer
53 views

Bash - Command substitution adds single quotes

I have a problem with bash behavior while evaluating grave accents. I want to run find with optional -name: find -name "*.log" works fine, but when i want to get the -name part from nested script ...
1
vote
2answers
34 views

Problem with using expr

I've got two strings str1="( 1 + 2 + 3 + 4 + 5 ) / 3 + 5" and str2="( 1 + 2 + 3 + 4 + 5 ) / 3 + 5 * 2" The command result=` expr $str1` returns a correct value, while result=` expr $str2` ...
0
votes
1answer
84 views

grep: Syntax error near unexpected token `('

I have this problem: I'm looking for a string inside file . Syntax is: grep -E ‘( ^ | [[:space:]] )[A-Z]{2}[[:digit:]]{2}((- | [[:space:]] )[[:alnum:]]{4}) {3} ’ (filename) When I run this ...
0
votes
2answers
90 views

Recursively remove files with idx > 10,000

The problem In the current working directory I have several (very many) folders and some of them have lots (like 100,000+) of files inside. My goal is getting just the folder with 10,000+ files and ...
1
vote
2answers
68 views

sed - doesn't append new line EOF and replaces letter not defined

I am experiencing a strange behavior using a sed command (got to be sed, no awk in this case) and got two questions for you, hoping someone got the skills to explain me what I am doing wrong. I want ...
1
vote
2answers
57 views

Splitting the working directory in a bash script

If a do: IFS="/" read -ra PARTS And type in a path manually, it creates the array "PARTS" as hoped, however: IFS="/" read -ra PARTS <<< $(pwd) creates an array with a single element, ...
4
votes
2answers
397 views

while: command not found

I'm trying to do this as an April Fool's prank: make a linux machine display a message in the shell every few seconds. My thought is to achieve this by starting an infinite loop that runs as a ...
1
vote
4answers
114 views

find: missing argument to `-exec'

when I'm trying to use this command var1=`sudo -u psoadmin -H -s ssh daill_scp@files.dc1.responsys.net find . -maxdepth 1 -type f -mtime +14 -exec ls -lh \{} \; | awk '{print $5, $9}'|egrep -v ...
3
votes
2answers
57 views

GNU Parallel: Event not found (!~)

About my code: get all .txt files for each file, execute the awk command. All files are processed in parallel if colum 3 does NOT contain "needle", write line to file Result: -bash: !~: event ...
-1
votes
2answers
29 views

Create new file with spaces from argument BASH [duplicate]

I need to create new file which contains spaces in it. And it is passed through the argument. This code below creates 2 sepate files. Can anyone help me how to create 1 file which will contains space? ...
2
votes
3answers
50 views

Command substitutions vs backslash escapes in a quoted string

Consider a double-quoted command substitution with backslash escapes inside it, like this: echo "$(echo '\\')" It prints out \\, whereas I would have expected it to print out only one backslash. My ...
-1
votes
1answer
39 views

Mutiple commands after sudo in one line

I want to execute multiple commands after a sudo command su - appuser -c "cd /apps/bundle/bundle-client/bin ; export BDL_WEB_USER=not_used ; export BDL_WEB_PASSWORD=not_used ; ./bundle -b ...
0
votes
1answer
86 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 ...
2
votes
4answers
178 views

How do I perform xargs grep on grep output that has spaces?

I'm searching for files based on a regular expression, and then I'm trying to search those files for content. So, for example, I have something like #Find all C++ files that match a certain pattern ...
1
vote
1answer
66 views

awk pattern with variable in a bash script

I have problem with command awk in bash I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line? awk -F" " "/$PWD/ {print $1,$3}" file.txt
1
vote
1answer
45 views

BASH: looping through ls [duplicate]

I'm having trouble with this piece of code: 22 for filename in "$( ls "$1" | grep ".*\.flac$" )"; do 23 file_path="$1${filename}" 24 ffmpeg -i "${file_path}" -f ...
0
votes
2answers
38 views

Why is wget still failing even after enclosing the URL with double quotes?

I enclose URLs I want to wget with "" since most of them have spaces, braces, etc. It usually works fine, but I can't get this URL to work: wget "http://xxxx/Sankarea - 6 - It`s Because I... Ran ...
1
vote
2answers
105 views

sh -c: Unterminated quoted string error [duplicate]

I've spent hours trying to understand the following error. My Script CMD="sh -c 'echo \"a\"'" $CMD Error: "a"': 1: "a"': Syntax error: Unterminated quoted string of course when I do echo $CMD ...
1
vote
2answers
278 views

How to put $@ in quotes?

My bash script looks like this: #!/bin/bash grep -r --color=always $@ . | nolong The file is saved in /usr/bin/findstr Everything's ok when I run this: findstr hello But when I run this: ...
4
votes
2answers
124 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...
1
vote
1answer
39 views

Replace a string in a text file using a shell script not working properly

I have a text file containing this: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1 and I want to replace the 1.0 to 2.0 so that it becomes: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1 so I use this ...
0
votes
2answers
110 views

ssh inside a script with 'command' instead of “command”

I am trying to run commands on various nodes of our cluster automatically via a simples script. I have seen that I can run: #!/bin/bash echo "Machine: "$HOSTNAME; ssh machine2 'echo Machine: ...
1
vote
4answers
54 views

echo \\* - bash backslash escape behavior, is it evaluated backwards?

So in bash, When I do echo \* * This seems right, as * is escaped and taken literally. But I can't understand that, when I do echo \\* \* I thought the first backslash escaped the second one ...
1
vote
1answer
54 views

How to pass a path to a file through a call to perl from bash?

This is a more advanced version of a previous question (How to pass arguments to perl when trying to change a line?) I made. This time I am trying to pass a path, but evertything seems that the the ...
1
vote
1answer
78 views

Create tar files from shell script with current time stamp

I am trying to create a shell script which will back up my git codebase and save in a specific back up directory with current days name So far I have : #!/bin/bash branch="master" if [ $# -eq 1 ] ...
1
vote
2answers
60 views

Single or Double quotes when defining an alias?

I know that contents of double quotes are expanded, whereas the contents of single quotes are not, such that echo '$1' gives $1 where as echo "$1" gives <the argument - blank in this ...
0
votes
1answer
242 views

Replacing white-space / characters with backslashes [duplicate]

I want to convert a bunch of mkvs to mp4s with the following command: for i in $(ls *mkv); do ffmpeg -i $i -vcodec copy -acodec copy $i.mp4; done; However, the filenames have whitespaces and ...
1
vote
2answers
76 views

Any special permission ssh remote command working on fifo file(aka named pipe)?

I need to redirect some strings to a fifo file with ssh remote command, but always got permission denied, the command I executed is: ssh rundeck@nagios1 sudo su - root -c 'printf ...
2
votes
2answers
42 views

Why is a variable passed to the su command, but not an array from the same scope?

In the example below, why does $var get passed to the su in the start function, but not the array modules ? #!/bin/bash var=cat modules=( one two three four ) start() { su gleventh -c "for i in ...
0
votes
2answers
33 views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
1
vote
1answer
49 views

ksh “<<EOF” script to change user

In the simplest form I am puzzled why this script does not work as expected as a here script changing users with su - user <<EOF. su - db2prd<<EOF PARMDATE=1111111 echo parmdate echo ...
1
vote
1answer
58 views

how to locate a name-not-specified file in bash? [closed]

I have a bash like this to easily upload a file to my server: FILE=../"$1"/1.txt scp 1.txt remoteserver #upload the file to a remote server. The $1 is for input directory and I have a lot of ...
4
votes
2answers
296 views

How to echo `single quote` when using single quote to wrap special characters in shell?

I'm reading shell tutorial today from http://www.tutorialspoint.com/unix/unix-quoting-mechanisms.htm In which it mentions: If a single quote appears within a string to be output, you should not ...
1
vote
3answers
54 views

how to express line feed in shell?

Im my debian7.8 bash shell. str="deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free \n deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free " echo $str > ...
2
votes
1answer
114 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...