0

I am trying to write a script that will upload a file via rest api. I am trying to show the action and its completion using echo statements as below..

echo "Uploading file ..."  
curl -s -u user:pass -XPUT https://mywebsite/api/filename  
echo "DONE."

I want the standard o/p to look like as below.

Uploading file ... DONE.

Is this possible using echo?

  • You really did some thorough investigation by yourself before asking here? –  Dec 02 '20 at 10:56

2 Answers2

1

You can group commands in curly braces and redirect the output for the whole command group:

{
  printf '%s' 'Uploading file ...'
  if curl -s -u user:pass -XPUT https://mywebsite/api/filename
  then outcome='DONE'
  else outcome='FAILED'
  fi
  printf ' %s.\n' "$outcome"
} >>logfile

Here, printf is used rather than echo to print the the 'Uploading file ...' text without a newline character, and the 'DONE.' text with an explicit newline.

Léa Gris
  • 17,497
  • 4
  • 32
  • 41
0

multiple commands are combine able using semicolon at the end of command as shown in below example

echo -e "Hello Kali " ; echo "Hello Debian" ; echo "Hello Arch" 

and to store its output on a variable kindly cover commands with parentheses as shown in below example.

a=$(echo -e "Hello Kali " ; echo "Hello Debian" ; echo "Hello  arch") ; echo $a

now kindly use your commands as per the requirement.

linux.cnf
  • 519
  • 6
  • 7