The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
1answer
35 views

Why doesn't PIPESTATUS work on pipelines within a command substitution

Proof below: Bash 4 Prompt> $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/') Prompt> for i in ${PIPESTATUS[@]}; do echo $i;done Output> 0 Prompt> echo hello|sed ...
1
vote
2answers
37 views

Why asterisk in command result in for loop is expanding?

I want to write a script that will run git diff --name-status master..<BRANCH> but when I run this: for i in $(git branch | grep -v master); do echo $i; done I get echo one directory ...
1
vote
1answer
27 views

S-Lang shell (slsh): capture command output in a variable

In slsh I know that I have to !-prefix a command to execute it: !ls How can I capture its output in a variable?
3
votes
2answers
133 views

Command substitution declaration syntax in bash - which of these two is better practice? [duplicate]

This is part of a bash find loop, and I wondered which is more correct syntax and why? filename="$(echo "$i" | cut -c5-)"; filename=`echo "$i" | cut -c5-`; Both function for the purpose of getting ...
5
votes
2answers
81 views

“command | less” vs “less <(command)”

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the ...
3
votes
2answers
32 views

How can I list the info for an array of /dev/disks using bash expansion or substitution?

I want the output of: diskutil list; diskutil info [multiple devices] Without having to do: diskutil info disk0; diskutil info disk0s1; diskutil info disk1 ...etc For example, with many builtin ...
1
vote
1answer
37 views

Does the command execute automatically when setting it to a variable?

I'm getting familiar with all about linux & shell/bash scrpiting. I'm configuring a backup script & it will compress an entire dir. I wanna know if I have to print the variable where the ...
4
votes
3answers
211 views

How do I read the output of commands in a script

I'm learning Linux scripting at the moment, and one thing I can get working is assigning a command output to a variable. The command service httpd configtest returns Syntax is OK, so I wrote this. ...
4
votes
2answers
108 views

Command substitution vs I/O Redirection?

I am wondered about differences between I/O Redirection and Command substitution? For example when I want to redirect which command output to cd command (I know that it's not a directory) then the ...
0
votes
1answer
64 views

Commands inside bash not being interpreted?

I'm trying to execute a command inside a bash script, $(pwd) is not being interpreted at all, and not even using eval. This do not work: cat apache-vhost.conf | sed 's/{path}/$(pwd)/g' Neither ...
2
votes
2answers
182 views

grep and directories containing spaces

I would like to search all files containing an association of strings (here the files should contain 'arthur' AND ('déni' OR 'deni') for instance) in a directory and subdirectories. After some search ...
16
votes
2answers
1k views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
1
vote
2answers
38 views

subsitute removing zero numbering

I would like to subsitute in a txt file the followings targets for example "code_000040" by "code_40" and "code_067340" by "code_67340" and so on.., in other words to remove the zeros in the 6 ...
3
votes
2answers
71 views

Inconsistencies between redirecting input from file, here docs, and here strings

Why is this inconsistent? I would expect here docs and here strings to be functionally equivalent to redirecting input from a file. $ bash --version GNU bash, version 4.1.2(1)-release ...
1
vote
1answer
62 views

Assignment to variables

I was trying to devise a solution to a different question asked on the site and came across this curious issue. Here is the set of commands that I issued: $ foo=82a9948422 $ echo $foo 82a9948422 $ ...
3
votes
1answer
212 views

variable expansion within command substitution over SSH bash 4.X

I want to do this ssh ${w100user}@web100 'ls -l "$(grep "${1}" /etc/pure-ftpd/pureftpd.passwd|cut -d':' -f6)"' Which obviously performs an ssh session to server web100 as w100user and then greps ...
1
vote
1answer
589 views

Basename gives extra operand error

I 'm using the following script to merge few pcap files into one using mergecap command. But when I run it it gives me a 'basename: extra operand /mnt/md0/capture/DCN/dcn_2014_02_04_00_11_47_598.pcap' ...
2
votes
4answers
193 views

Using a generated list of filenames as argument list — with spaces

I'm trying to invoke a script with a list of filenames collected by find. Nothing special, just someting like this: $ myscript `find . -name something.txt` The problem is that some of the pathnames ...
0
votes
1answer
155 views

How to escape spaces while using command's output in command line [duplicate]

I want to perform the following command in command line : $ md5sum $(find . -type f) But this would cause problems when it encounter files with spaces in filenames : md5sum: Kaufmann: No such ...
3
votes
2answers
158 views

Command substitution interpreting spaces within quotes as argument separators

I'd like an alias that additionally appends itself to ~/.bashrc, e.g. function tailias { $(echo "alias $1='${*:2}'" | tee -a ~/.bashrc) } I'm using tee to split the command to ~/.bashrc while ...
1
vote
5answers
3k views

Pass the output of previous command to next as an argument

I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4). The output line can have the following value: rate (10%) - name: value - 10Kbps I want to grep that output in order to ...
2
votes
2answers
78 views

Piping to the command substitution of a string containing pipes

This works— $ x='grep a' $ echo ab | $x ab This doesn't— $ x='grep a | grep b' $ echo ab | $x grep: |: No such file or directory grep: grep: No such file or directory grep: b: No such file or ...
2
votes
1answer
154 views

What does the expression $(<“dir/file”) mean in bash?

In a bash script I cannot post here I see the following expression: $(<"dir/file") From what I understand the expression $(...) evaluates a command inside (as when using backticks), but what is ...
2
votes
1answer
136 views

Can't echo or create a symbolic link to a file with special characters in its name inside bash script

I'm trying to create a symbolic link to files with the following naming convention: .$abc$namehere.zip;1 As can be seen, it has the following special characters in it: . $ ; In my bash script I ...
4
votes
2answers
226 views

Word-splitting when parameter is used within command substitution

What needs to be done to ensure that a parameter containing embedded spaces is handled correctly when used within a command substitution? Perhaps an example will illustrate $ file="/home/1_cr/xy z" $ ...
0
votes
1answer
884 views

Getting a date format with grep

I've looked at similar questions and tried most suggestions, but none of them got me anywhere, even though i have a fairly simple task I think :S. I'm fairly new to this whole thing, so I've run out ...
4
votes
1answer
167 views

What does the command “$()” do in UNIX?

What does the command $() do in UNIX? Could someone explain what is the significance of $ in the below examples; $(echo var=10) and eval $(echo var=10)
8
votes
3answers
632 views

Trapping errors in command substitution using “-o errtrace” (ie set -E)

According to this ref manual: -E (also -o errtrace) If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR ...
1
vote
4answers
258 views

Command substitution grepping ls output causes error

I'm trying to make a tar.tgz file using command substitution There are backups of 17 Aug 2012 -rw-r----- 1 ossec 502 804M Aug 17 2012 BKPMDISINT_i6nir20j.F_bkp -rw-r----- 1 ossec 502 2.7G Aug 17 ...
4
votes
4answers
131 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
1
vote
2answers
50 views

Adding commands to VIM?

I keep accidentally entering W instead of w as the command to save my changes. Is it possible to create a shortcut, alias, or command to write, and give it the hotkey of W?
6
votes
2answers
553 views

Special character '#' in Perl SSH command

I try to send command using SSH in my perl script with # but it gets truncated right at # Example: Input text is : $message = "Product ID # STK000134" The SSH command is : $execute=`ssh -q ...
2
votes
5answers
258 views

Command substitution - single quotes and spaces

How can I make command substitution pass a list of single-quoted POSIX paths separated by spaces? command1 $(command2) command1 '/path/to/file 1' '/path/to/file 2' '/path/to/file 3' How can I trace ...
2
votes
1answer
626 views

Compare two data streams without both being stored as files

I have these two files:- [root@localhost base_filters]# cat aix_old joe amadeus image bill juliet charlie romeo ftp [root@localhost base_filters]# cut -d: -f1 passwd2 henry amadeus image bill julie ...
0
votes
1answer
281 views

Command substitution in alias resolved in bash profile? [duplicate]

I want to make an alias for randomly changing my mac address alias chrandmac="sudo ifconfig en0 ether $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')" but the command substitution part is ...
1
vote
1answer
102 views

starting vim with command substitution

I am working on a project on two different machines - one running Mac OSX 10.8.3, and one running Red Hat Enterprise Linux. On my Mac, I can do this: vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp)) and ...
3
votes
1answer
103 views

Different behavior of $() and `` [duplicate]

% PATH="MYPATH" % VAR="PATH" % echo $(eval echo \$$VAR) MYPATH % echo `eval echo \$$VAR` 5707VAR ^^ This is the process number. I thought those two were exactly the same, but obviously there are ...
1
vote
2answers
78 views

Configure bash to execute command with last argument when no argument was provided

I would like to configure bash so that when I execute command (preferably from a list of commands, not any command) without an argument, it takes the argument of previous command. So, for example I ...
2
votes
2answers
388 views

How to pass the output of a script to a command like ls without the output being split?

Suppose I have a script like this: #!/bin/bash printf '%q\n' "b c" Executing the script prints: b\ c on the commandline. Now, being in a directory which contains a file named b c I want to pass ...
2
votes
1answer
1k views

How does wc -l `ls` give the actual number of lines?

Can anyone explain to me how does this command work. wc -l `ls` while this command gives the total number of java lines or txt lines.
1
vote
5answers
741 views

Run a command on all the files in a directory tree and put the output into a variable

I want to run this bash command : #!/bin/bash rep="*" for f in `ls -R`$rep; do d='git log '$f'| wc -l' c=$d echo $c done how to excute a command git log myFile | wc -l from bash ? ps : this ...
8
votes
3answers
7k views

Understanding backtick (`)

I am trying out the command $ b=5; echo `$b`; -bash: 5: command not found but it does not print 5 as it is supposed to. What am I missing here? What does ` (backquote/backtick) mean in bash? seems ...
4
votes
3answers
2k views

Split command output by linebreak?

I have a command returning multiple lines. For further processing I need to process each single line of those lines. My current code works by modifying the IFS (Internal Field Separator): ...
2
votes
1answer
388 views

Command substitution: file or command not found

The following script #!/bin/bash QUERY='select * from cdr;' MYROWS=$("sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db '${QUERY}'") gives me ./bla.sh: row 35: sqlite3 -list ...
7
votes
3answers
3k views

Multivariable For Loops

Is there a way to specify multiple variables (not just integers) in for loops in bash? I may have 2 files containing arbitrary text that i would need to work with. What i functionally need is ...
3
votes
1answer
332 views

Command substitution: cat with executable content

I have a file called test and the contents are: ubuntu@regina:~$ cat test ** test ** catting this file via command line works fine, but if I use command substitution I get an understandable but ...
10
votes
4answers
8k views

Command substitution: splitting on newline but not space

I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it. I have a file with contents ...
1
vote
2answers
546 views

Create MySQL database name using variable from date

for the variable dbnya="echo $(date +%Y%m%d%H%M%S)" When running below code, I will get an error (SQL syntax error) mysql -u root -pthepass -e "CREATE DATABASE demo$dbnya CHARACTER SET utf8 ...
18
votes
1answer
4k 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 ...
5
votes
1answer
4k views

Bash: Merge foldername from variable with filename

First I write a configfile with all my parameters like this path="/home/test/" I name it test.conf. Then I write a shell script with this content, name it test, and make it executable with chmod ...