0

So, the PHP script returns (or maybe needs to echo the value?) a value, e.g. 32, I want the rest of the alias to rename file test.txt to test32.txt, so to append THAT value (32) to test and append then the value .txt, so to rename it. What is the command to take this value from PHP and use it in command mv test.txt test32.txt ?

Tha PHP script that I run is:

php getValue.php 

This command returns a number value (e.g. 32).

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Vladimir Despotovic
  • 3,200
  • 2
  • 30
  • 58

2 Answers2

3

Have PHP print the value to stdout:

<?php
echo 32;

Then use command substitution to capture the output as a string:

#!/bin/bash

mv test.txt "test$(php getValue.php).txt"
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
0

getValue.php:

<?php
echo rand(0,100);
?>

script.sh:

#!/bin/bash
phpvalue=`php getValue.php`

file=$1
extension="${file##*.}"
filename="${file%.*}"
mv "$file" "${filename}${phpvalue}.${extension}"

Example usage: ./script.sh test.txt

mikaelwallgren
  • 310
  • 2
  • 9