command-substitution

set environment variable in GDB from output of command

末鹿安然 提交于 2020-03-17 13:19:08
问题 I am trying to exploit a buffer overflow in a challenge, the buffer gets it's value from an environment variable. In GDB I know that you can set environment variables using the command: set environment username = test However I need to pass the username variable special characters, so I need to do something like: set environment username= $(echo -e '\xff\x4c......') But that command doesn't get executed and the username variable contains literally what I wrote down, does anybody know a trick

set environment variable in GDB from output of command

血红的双手。 提交于 2020-03-17 13:12:06
问题 I am trying to exploit a buffer overflow in a challenge, the buffer gets it's value from an environment variable. In GDB I know that you can set environment variables using the command: set environment username = test However I need to pass the username variable special characters, so I need to do something like: set environment username= $(echo -e '\xff\x4c......') But that command doesn't get executed and the username variable contains literally what I wrote down, does anybody know a trick

Backticks vs braces in Bash

拜拜、爱过 提交于 2020-01-08 14:10:21
问题 When I went to answer this question, I was going to use the ${} notation, as I've seen so many times on here that it's preferable to backticks. However, when I tried joulesFinal=${echo $joules2 \* $cpu | bc} I got the message -bash: ${echo $joules * $cpu | bc}: bad substitution but joulesFinal=`echo $joules2 \* $cpu | bc` works fine. So what other changes do I need to make? 回答1: The `` is called Command Substitution and is equivalent to $() (parenthesis), while you are using ${} (curly braces

Bash IFS ('\n'): Problems with file name detection through find command and for loop

南笙酒味 提交于 2020-01-05 03:33:12
问题 #!/bin/bash IFS='\n' declare -i count=0 AX=$(find *.iso -maxdepth 1 -type f) # Rather use AX="$(find *.iso -maxdepth 1 -type f"? # A="${AX%x}" < Could I use this when applying "" to $() in AX? But it should already include newlines like this way. edit: I don't need the trailing newlines fix. for iso in "$AX" do echo "Use "$iso"? [Y/N]?" # Outputs ALL files, IFS has no force somehow read choiceoffile shopt -s nocasematch case $choiceoffile in y ) echo "Using selected file.";; * ) continue;;

Bash IFS ('\n'): Problems with file name detection through find command and for loop

烈酒焚心 提交于 2020-01-05 03:32:13
问题 #!/bin/bash IFS='\n' declare -i count=0 AX=$(find *.iso -maxdepth 1 -type f) # Rather use AX="$(find *.iso -maxdepth 1 -type f"? # A="${AX%x}" < Could I use this when applying "" to $() in AX? But it should already include newlines like this way. edit: I don't need the trailing newlines fix. for iso in "$AX" do echo "Use "$iso"? [Y/N]?" # Outputs ALL files, IFS has no force somehow read choiceoffile shopt -s nocasematch case $choiceoffile in y ) echo "Using selected file.";; * ) continue;;

Interpreting command substitution from a variable in bash

随声附和 提交于 2019-12-24 11:03:47
问题 For the following value of FOO: $ FOO='echo `echo hello`' $ $FOO `echo hello` how can I get the expected output: hello Basically, how can I interpret a command substitution in the contents of a variable? 回答1: Answering the question as given, eval $FOO but you're probably going about your real problem the wrong way. 回答2: Try this $ FOO="echo `echo hello`" $ $FOO Just replace single quotes with double quotes . 来源: https://stackoverflow.com/questions/11531332/interpreting-command-substitution

How to use case/esac in process substitution?

落花浮王杯 提交于 2019-12-24 02:11:17
问题 I've the following line which works fine: while getopts :t t; do case $t in t) echo $t; break; esac; done however when I'm trying to use it as command substitution, the bash fails with error. Code: #!/usr/bin/env bash echo $BASH_VERSION [ "$(while getopts :t t; do case $t in t) echo $t; break; esac; done)" = "t" ] && echo "Option specified." Result: $ ./test.sh -a -b -c -t 4.3.42(1)-release ./test.sh: line 3: unexpected EOF while looking for matching `"' ./test.sh: line 4: syntax error:

How do I assign the output of a command into an array?

我只是一个虾纸丫 提交于 2019-12-17 05:46:07
问题 I need to assign the results from a grep to an array... for example grep -n "search term" file.txt | sed 's/:.*//' This resulted in a bunch of lines with line numbers in which the search term was found. 1 3 12 19 What's the easiest way to assign them to a bash array? If I simply assign them to a variable they become a space-separated string. 回答1: To assign the output of a command to an array, you need to use a command substitution inside of an array assignment. For a general command command

How to avoid bash command substitution to remove the newline character?

天大地大妈咪最大 提交于 2019-12-17 03:03:11
问题 To speed up some bash script execution, I would like to keep the result of a command in a variable using command substitution, but the command substitution replaces the 0x0A newline character by a space. For example: a=`df -H` or a=$( df -H ) When I want to process further $a , the newline characters are replaced by a space and all the lines are now on one line, which is much harder to grep: echo $a What would be the easy tricks to avoid the newline character being removed by the command

Multi-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped to

妖精的绣舞 提交于 2019-12-10 03:41:44
问题 I am on GNU bash, version 4.3.11. Say I want to print unique lines on a file. I am using this approach, which works well on a file: $ cat a 9 10 9 11 $ awk '!seen[$0]++' a 9 10 11 However, if I get the input from stdin, using double quotes in a multi-line and piping to awk, it fails: $ echo "9 > 10 > 9 > 11" | awk '!seen[$0]++' bash: !seen[$0]++': event not found That is, bash tries to expand the command seen , which of course does not know because it is a variable name. But it shouldn't