0

I have two scripts used to setup perf on an embedded linux system and they work fine except for the last line

#!/bin/bash


sudo route add -net 192.168.2.0 gw 192.168.42.1 netmask 255.255.255.0 

scp -P 23 ~/perf_p7/perfSetup.sh 192.168.42.1:../tmp 

ssh -p 23 192.168.42.1 bash ../tmp/perfSetup.sh

and

#!/bin/bash


mkdir /mnt/buildroot-target

IP=192.168.42.2 

nfs.sh ${IP}

mount -o nolock,proto=tcp,addr=${IP} -t nfs ${IP}:/home/vclement/sfx1_build/Binaries/p7-arm/master/buildroot/target /mnt/buildroot-target/ 

alias perf='LD_LIBRARY_PATH=/mnt/buildroot-target/usr/lib  /mnt/buildroot-target/usr/bin/perf'

alias perf='LD_LIBRARY_PATH=/mnt/buildroot-target/usr/lib /mnt/buildroot-target/usr/bin/perf' does not seem to work however when I run it manually in the console, it works just fine in order to let me use the "perf" command directly.

If anybody has any idea why that is or has a fix, thanks for letting me know

Dummy00001
  • 16,630
  • 5
  • 41
  • 63
VictorC
  • 71
  • 7
  • 1
    What are the steps you follow? If you run the script, the alias is set in the subshell, so when it finishes you cannot access `perf` because you are in a different shell. – fedorqui Apr 18 '16 at 08:09

2 Answers2

0

The problem is that alias is a built-in command for bash. Its effect is lost when the script ends.

If you want it to apply to your current shell as well you have to 'source' the second script, either:

source ./<scriptname>

or:

. ./<scriptname>
NZD
  • 1,780
  • 2
  • 20
  • 29
  • I modified the first file with the two suggestions but it does not seem to change much. Should I maybe use something else than alias for the 'perf' shortcut to be be available on the device? – VictorC Apr 18 '16 at 13:27
0

You can use functions. They are more appropriate for something more complex then just simple commands:

function perf() {
  LD_LIBRARY_PATH=/mnt/buildroot-target/usr/lib  /mnt/buildroot-target/usr/bin/perf
}
Jakuje
  • 24,773
  • 12
  • 69
  • 75