0

I have this bash file which generates key and expire time :

#!/bin/bash
get_customer_url() {
  local IP=${1:-127.0.0.1}
  local SECRET=${2:-VERY_COOL_SECRET}
  local EXPIRES="$(date -d "today + 30 minutes" +%s)";
  local token="$(echo -n "${EXPIRES} VERY_COOL_SECRET" | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =)"
  echo "/${token}/${EXPIRES}/"
}
get_customer_url

and i call it via php like this

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?>

it works fine , it generates something like this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 

my problem is i want to put another php result in the some line like this

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?><?php echo get_post_meta($post->ID, 'file', true)?>

currently its printing the result in two lines i need it to be one just one line instead of this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 
file.mp4.m3u8

i want it to be like this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/file.mp4.m3u8

without white spaces or multiple lines !

anofl sogodi
  • 11
  • 1
  • 4
  • 3
    Why all of this when you can do it all in PHP alone? See also [generate random key in PHP](https://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php). – tadman Jun 28 '18 at 21:19
  • @LioraHaydont Why would that help? `echo` doesn't add a newline by itself. – Barmar Jun 28 '18 at 21:25
  • @Barmar ah, I forgot about that, sorry – Liora Haydont Jun 28 '18 at 21:28
  • I don't know how to convert the bash script to php , if someone can convert it to me i would very appreciate it ! – anofl sogodi Jun 28 '18 at 21:28

1 Answers1

0

Remove the whitespace around the result of shell_exec().

echo trim($output);
Barmar
  • 741,623
  • 53
  • 500
  • 612