Linked Questions

14 votes
3 answers
19k views

How to echo multi lined strings in a Bourne shell [duplicate]

I want to create some scripts for filling some templates and inserting them into my project folder. I want to use a shell script for this, and the templates are very small so I want to embed them in ...
  • 55.5k
5 votes
1 answer
20k views

SHELL add double quotes at the beginning and end of specific variable [duplicate]

I have variable in shell script which takes a value in variable $var1. If I do echo $var1 I will get for example value Boston. My desired value is "Boston" I tried couple of cases: var1=""$var1"" ...
  • 1,668
6 votes
3 answers
3k views

What is the difference between "$a" and $a in unix [duplicate]

For example: #!/bin/sh a=0 while [ "$a" -lt 10 ] b="$a" while [ "$b" -ge 0 ] do echo -n "$b " b=`expr $b - 1` done echo a=`expr $a + 1` done* The above mentioned script ...
36 votes
0 answers
19k views

Invalid string: control characters from U+0000 through U+001F must be escaped using Bash? [duplicate]

I have a function like: getServers() { curl -s -X GET ... } The output is a complex JSON string. I can parse the JSON like this: serverId=$(getServers | jq -r ".[] | select(whatever...)"...
  • 2,739
0 votes
2 answers
13k views

Getting "[: =: unary operator expected" in a bash program [duplicate]

I've been working on a sample bash program to practice bash scripting, but whenever I try to run it with the correct variables, it outputs "[: =: unary operator expected" and quits. #! /bin/...
6 votes
1 answer
2k views

How to preserve trailing whitespace in bash function arguments? [duplicate]

Consider the following bash script: #!/bin/bash function foo { echo -n $1 echo $2 } foo 'Testing... ' 'OK' # => Testing...OK # Whitespace --^ ^ # Missing whitespace -----...
  • 149k
-1 votes
2 answers
7k views

what is the difference between $1 and "$1" in bash script? [duplicate]

example while [ -n "$1" ] do something done can i write $1 instead of "$1"? And what is the difference between user=alexander and user="alexander"? Thanks
  • 818
3 votes
2 answers
875 views

Why cURL outputs process name? And how to get rid of it? [duplicate]

Usually when you use cURL the output looks like that: alex$ curl http://some-url some-content But, for some urls the outputs is different: alex$ curl http://some-url [1] 81030 alex$ some-content [1]...
  • 13.1k
0 votes
3 answers
12k views

AIX / Unix - Delete files older than x days [duplicate]

I have been struggling with this one for quite a few days now. It seems simple enough but I cannot seem to find the right command or arguments needed to accomplish this (seemingly) simple task. I ...
3 votes
2 answers
3k views

Why do I use double quotes in shell scripts [duplicate]

I understand the usage single quote and double quote. but I don't know situation need to double quotes in the script. there is no diff that statements $ echo hello world! $1 $ echo "hello world! $1"...
user avatar
1 vote
1 answer
3k views

check if variable exist using if else bash script [duplicate]

I try to write a very simple bash script file named bash_script.sh #!/bin/bash if [ -z $1 ];then echo $1 else echo 'no variable' fi in the terminal I tried to run ./bash_script.sh ...
  • 313
5 votes
1 answer
679 views

When should I double-quote a parameter expansion? [duplicate]

Say I have a variable x. When expanding it, should I use $x or "$x"? (This is intended as a canonical duplicate for any question that revolves around unquoted parameter expansions.)
  • 485k
1 vote
2 answers
3k views

append json array using jq [duplicate]

I have a json file which I am fetching from consul and the results are very simple: [ { "name" : Jon", "class" : "senior" } ] I want to update the array with below ...
0 votes
2 answers
6k views

jq not parsing json with spaces [duplicate]

I’m trying to run the following command that reads JSON from a file and formats it with jq : jq -n -r --arg m $(<$1) '$m | fromjson | {records:[{value:.}]}' It produces the desired output when ...
1 vote
1 answer
8k views

`sed: -e expression #1, char 1: unknown command: `,'` [duplicate]

I get the below error on running above command from shell script in CYGWIN. Error: sed: -e expression #1, char 1: unknown command: `,' IF I ran command in cmd: $ sed -n "8937,8946 p" "/cygdrive/...

15 30 50 per page
1
2 3 4 5
52