Can't get executable shell script to show output in Terminal

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
dreamkatcha

Can't get executable shell script to show output in Terminal

Post by dreamkatcha »

Hi,

That just about says it all. I want it to, but it's not doing. I can't find anything in the preferences or properties menus of either Terminal or the shell script to allow me to do this so when I execute saved scripts I have to just cross my fingers and hope it's doing what it's supposed to, which is hardly ideal. Any ideas would be greatly appreciated please.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
kurotsugi

Re: Can't get executable shell script to show output in Term

Post by kurotsugi »

Code: Select all

run-parts /path/to/script.sh > ~/kuroz.log
we can also include a log file or an echo flag to see whether if the script working or not. here's one of my script

Code: Select all

#!/system/bin/sh
# kuro flappy: flappy bird cheat script
# copyright@mycat (2012) - lol...i'm just joking. no copyright or whatsoever
# contact : kaze.noichi17@gmail.com

LOG_FILE=/data/kuroz.log
DIR=/data/data/com.dotgears.flappybird/shared_prefs
if [ -e $LOG_FILE ]; then
	rm $LOG_FILE;
fi;

# the preface
echo "==========================
#  TWEAK AKURO-LOG FILE  #
==========================
in the name of Allah, 
the most beneficent, 
the most mercifull
==========================
system information:
vendor   : $( getprop ro.product.brand )
model    : $( getprop ro.product.model ) 
ROM      : $( getprop ro.build.display.id )

running the script...
start at: 
$( date +"%m-%d-%Y %H:%M:%S" )
==========================" >> $LOG_FILE;

# the real script start here
CHEAT=/sdcard/score
if [ -e $CHEAT ]; 
then
	mv $DIR/FlappyBird.xml $DIR/Flappy
	echo -e "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<int name=\u0022score\u0022 value=\u0022$(cat $CHEAT)\u0022 />
</map>" >> $DIR/FlappyBird.xml; 
else
	mv $DIR/FlappyBird.xml $DIR/Flappy
	echo -e "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<int name=\u0022score\u0022 value=\u00225012\u0022 />
</map>" >> $DIR/FlappyBird.xml;
fi;

echo "SUCCESS!
your score have been updated" >> $LOG_FILE
# end
echo "==========================
done at: 
$( date +"%m-%d-%Y %H:%M:%S" )
all praise is due to Allah
==========================
--   have a nice day    -- 
      kurotsugi@xda
==========================" >> $LOG_FILE;

notice the "#!/system/bin/sh" that was a script for android but the trick should work on linux too. if you don't want to create log files you can use "echo" command as a notice

Code: Select all

#!/bin/bash
<whatever script you have here>
echo "success"
exit 0
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Can't get executable shell script to show output in Term

Post by Pilosopong Tasyo »

Moved from Xfce as this is a scripting question.

If you're running the scipt directly from the GUI, try this hack.
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
dreamkatcha

Re: Can't get executable shell script to show output in Term

Post by dreamkatcha »

Thanks for the replies. I'll give those suggestions a go.

Yes, I'm running it from the GUI i.e. double-clicking the script's icon in Thunar running on Mint XFCE. In Mate there are options within the properties menu in the file manager that let you decide how you would like to run the script and what should happen to the Terminal when the script has executed.
Locked

Return to “Scripts & Bash”