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

learn more… | top users | synonyms

1
vote
1answer
33 views

Can see file in /usr/local/bin with ls, but attempting to run it yields file not found?

I'm on OS X, but since this is terminal work I figured this was the best place to ask. I'm trying to get Sublime Text to work at the command line via subl and having no luck. I ran ln -s <location ...
2
votes
1answer
31 views

View remote value of $PATH inside shell script

When executing this bash script, it only shows my local path. ssh ${REMOTE_HOST} 'bash -s' <<EOL set -e source ~/.profile echo $PATH # Commands here don't work because $PATH is ...
-1
votes
2answers
57 views

bash scripting and PS1 prompt

Im trying to customize the way the PS1 prompt shows in terminal and CLI on Arch Linux, but it's not printing the proper thing it should be doing. First up is I'm trying to colorize parts of the PS1 ...
0
votes
1answer
42 views

Binary not accesible from Bash despite being in path

I am learning how to program in Racket. It's binary is in "/Applications/Racket v6.2/bin/racket". Let me show what happens: MacBook:~ enedil$ echo $PATH /Applications/Racket\ ...
-1
votes
1answer
55 views

Pass string value to date in Unix

mm="27 Jun 2011" dd=$(date -d'27 Jun 2011' +%Y%m%d) echo $dd I want to use value of mm in second line. When i tried like below dd=$(date -d'$mm' +%Y%m%d) It is giving error.
6
votes
4answers
822 views

Add a newline into a filename with `mv`

It's a serious question. I test some awk scripts and I need files with a newline in their names. Is it possible to add a newline into a filename with mv? I now, I can do this with touch: touch ...
0
votes
2answers
52 views

How do you search ! in man sed?

You cannot search ! directly because it puts process behind. For instance, you cannot search ! in sed man. How can you search ! in man?
2
votes
2answers
52 views

ssh command with quotes

I have an odd error that I have been unable to find anything on this. I wanted to change the user comment with the following command. $ sudo usermod -c "New Comment" user This will work while ...
0
votes
0answers
22 views

Run a command stored in a variable [duplicate]

I am working on updating some scripts we have used previously ( on RHEL) to work for a new flavor of Linux (ESX). As I am modifying the script, I wanted to add user feedback as well as some other ...
2
votes
2answers
166 views

Slash and backslash in sed [duplicate]

I want to use sed to change a slash into a backslash and a slash, i.e. / -> \/. But it does not work. Here a small example: #!/bin/bash TEST=/etc/hallo echo $TEST TEST=$(echo $TEST) echo $TEST ...
1
vote
2answers
43 views

Unable to store ascii value in a variable

I am trying to convert hex to decimal to ascii and store it in a variable. I am using the following code. HEX=30 DEC=`printf "%d\n" 0x${HEX}` echo "$DEC" ASC=`printf \\$(printf '%03o' $DEC)` echo ...
0
votes
1answer
29 views

Combine curl and base64 into one command?

I'd like to POST the Base64 encoding of a file to a server, combining curl and base64 into one command that I can execute. I've tried the following: curl 'http://localhost:5000/files' -X POST -H ...
2
votes
1answer
23 views

ssh not showing full output of command

I have a list of servers 20+ that I would like to get the shell that they are using. While logged onto a server I can run the following command $ ps -p $$ PID TTY TIME CMD 12022 pts/6 ...
0
votes
3answers
57 views

In bash, how to call a variable and wrap quotes around its value as part of a command without causing the variable name to become a string literal?

So I want to add 10 seconds to a time. The command to do that came from here. To illustrate: STARTIME="$(date +"%T")" ENDTIME="$STARTIME today + 10 seconds" CALL="$(echo date -d $ENDTIME ...
0
votes
1answer
36 views

What does “\(\)” stand for in this command: grep(“-(mean|std)\(\)”, x[,2])

Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])
2
votes
3answers
38 views

grep .* returns results from .bash_history and complains about

I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content: Lady of ...
3
votes
1answer
126 views

Bash substitution with variable defined from a glob pattern

The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution? #!/bin/bash FILEPATH_WITH_GLOB="/home/user/file_*" ...
1
vote
3answers
80 views

Is there any way to print value inside variable inside single quote?

Consider I've set variable site and needs to be printed by echo or printf, but If I use single quote to write something and want to use variable then how? Example: $ site=unix.stackexchange.com $ ...
1
vote
2answers
42 views

How to use multiline as group-separator in grep?

In grep you can use --group-separator to write something in between group matches. This comes handy to make it clear what blocks do we have, especially when using -C X option to get context lines. $ ...
4
votes
4answers
54 views

Echoing something with multiple quotes and key characters (&, $, !, etc.)

Let's say you have to echo this into a file: RZW"a4k6[)b!^"%*X6Evf How do you do it? My actual "line" to echo is a 2048 characters line.
0
votes
3answers
58 views

backup script to copy files by its extension

I have created script to copy .png files from one directory to another. Script is as follows: i="`cat /usr/local/app1/default.conf | grep -i values | sed -e 's/\values=//g' -e 's/,/ /g'`" for data ...
1
vote
1answer
45 views

Nested quotes in subshells

Say I have to use quotes to encapsulate subshell output like: DATA="$(cat file.hex | xxd -r)" But I need to nest this kind of stuff like: DATA="$(cat file.hex | xxd -r | tr -d \"$(cat ...
0
votes
4answers
93 views

Get process elapsed time in seconds

Similar to How to check how long a process has been running?, I am trying to get the elapsed time for a process in seconds in an embedded Linux system using BusyBox and sh (not bash). The difference ...
6
votes
5answers
850 views

Deleting files with spaces in their names

I am trying to delete all the files with a space in their names. I am using following command. But it is giving me an error Command : ls | egrep '. ' | xargs rm Here if I am using only ls | egrep '. ...
2
votes
1answer
48 views

grep misreads pattern from variable

I have a problem with escaped pattern put in grep. My test file is: export_cc = ${dir}/aaa/bbb/ccc export_cc = ${dir}/aaa/bbb/eee export_cc = ${dir}/aaa/bbb/ddd export_cc = ${dir}/aaa/bbb/fff ...
0
votes
1answer
44 views

tar exclude files *.zip

Why don't *.zip patterns work in tar : tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir Is there another syntax?
20
votes
4answers
2k views

How can I delete a file named “>”?

I was running a Python script that malfunctioned and used sudo to create a file named >. How can I get rid of this file? Of course, when I try sudo rm >, I get the error bash: syntax error ...
2
votes
2answers
145 views

bash: can't set a variable to a solid string [duplicate]

I cannot set a variable with a whole command-string as following: A="/bin/ps wwwaux" for a in $A do echo "$a" done It assigns array instead of solid string somewhy. Could you assist, please. My ...
0
votes
2answers
35 views

sed replace ;“ content with ';”

I have files that contain ;" and I need it replaced with ';" The following sed command does not work: sed -i "s/;"/';"/g" /root/bashy.sh How can I do this? The solution doesn't have to be sed.
8
votes
1answer
413 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 ...
1
vote
5answers
77 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
199 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
53 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
46 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
144 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
237 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
44 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
161 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
107 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
30 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
92 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
59 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
59 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
31 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
63 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
37 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` ...
1
vote
1answer
138 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
99 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
75 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
61 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, ...