Linked Questions

158
votes
5answers
526k views

How can I get the current working directory? [duplicate]

I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working ...
23
votes
4answers
110k views

Storing output of command in shell variable [duplicate]

I have an operation using cut that I would like to assign result to a variable var4=echo ztemp.xml |cut -f1 -d '.' I get the error: ztemp.xml is not a command The value of var4 never gets ...
12
votes
5answers
2k views

Why is my Bash script returning a syntax error? [duplicate]

I am writing a script which loops into recent files in a folder and executes a command... #!/bin/bash cd /home/Downloads recent_files = ($(ls -t | head -20)) for file in "${recent_files[@]}" do ....
0
votes
2answers
14k views

curl command output in a variable [duplicate]

I am connecting to mySQL database using a shell script. After connecting to the mySQL database, I execute a query. The query gives me 300,000 URLs as the result. For each of the 300,000 URLs I need ...
0
votes
1answer
6k views

How to use pipe to assign a variable [duplicate]

How can I assign value of $x1+$x2 to bc by piping? here in my code $bc holds no value. echo -n 'value x1 : ' read x1 echo -n 'value x2 : ' read x2 echo $x1+$x2 | bc echo $bc
0
votes
1answer
4k views

wc -l file to a variable [duplicate]

Given a filepath, I would like to find out how many lines there are and store them into a variable. For example: /three_little_pigs.csv straw wood bricks In a file, I would like to have the number (...
0
votes
2answers
7k views

How to read the output of a previous command in a shell script? [duplicate]

I executed a command in a shell script and the command ends with "completed successfully" or "completed unsuccessfully". How can I read that in the script and use it for if and else conditions?
0
votes
1answer
974 views

set a BASH variable equal to the output from 'top' command? [duplicate]

I know how to set a BASH variable equal to the output from a command, but it doesn't work in case of 'top' command for me, see below cat aTOPFWK.sh OUTPUT = $(top -b -n 1 | egrep 'fwk3' | awk '{...
2
votes
2answers
192 views

bash script to echo wan ip [duplicate]

The following bash script is expected to echo the current ip of the wan, instead of google "what is my ip". Error: ./ipChange.txt: line 2: +short: command not found “?? #!/bin/bash ip=dig +short ...
0
votes
2answers
1k views

How do I assign last month's date (year and month only - 2016-07) as a variable? [duplicate]

I am having trouble with using date as a variable in a bash script. I will admit that I have zero experience writing anything – in bash or otherwise – but I’ve been tasked with figuring this out. I ...
0
votes
1answer
402 views

How capture remote ssh output into a variable [duplicate]

I would like to know how to capture the output of this command into a variable ssh -q $ssh_host 'ps -eo comm,lastcpu' Once the information is captured, I want to check the variable if it returned ...
1
vote
1answer
282 views

Saving find command output to variable [duplicate]

I'm trying to save the find output to a variable in this manner: a=find /Users/Downloads/DTI_allsites/subprojects/*/UII_0077 -name "dti_preprocessed" -type d But I keep getting the following ...
2
votes
2answers
48 views

Linux Bash: Variable to another variable [duplicate]

i have this: echo $MSG | sed -e $'s/;/\\\n/g' I want to put the result of that sed in a new variable called $MSG2 Something like: $MSG2=echo $MSG|sed -e $'s/;/\\\n/g' How can i do it? Thank you!...
-6
votes
1answer
396 views

Assign output to variable in Shell [duplicate]

a=Hello-World b=$(a|cut -d- -f1) echo "$b" The above commands are not working for me. Any input?
0
votes
1answer
139 views

How to put whereis result into cd? [duplicate]

My format is whereis directory | cd but I get no output (not even a warning). Where as you have other posts that require variables, my question asks how to do it without them.

15 30 50 per page