2

I run a command at the command line and it works fine. I have added the same command to a bash script and it cuts the output. I have made sure the quotes are correct and I can't seem to see where I am going wrong.

This is the command when I run it manually:

./ciscocmd -u username -p password -s passwowrd -t 192.168.1.1 -c "show mac address-table address 34e6.xxxx.xxxx"

and it shows

Processing... 192.168.1.1
switch#show mac address-table address 34e6.xxxx.xxxx
Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
10    34e6.xxxx.xxxx    DYNAMIC     Gi0/2
Total Mac Addresses for this criterion: 1

This is in the script:

portis=`./ciscocmd -u username -p password -s passwowrd -t 192.168.1.1 -c "show mac address-table address 34e6.xxxx.xxxx"`
echo $portis

but yet it outputs this

[root@server]# ./test.sh
switch#ddresses for this criterion: 1--4e6.xxxx.xxxx
[root@server]#

I must be missing something. I have tried double "" and '' to surround the mac address but its not working.

Any suggestions?

3
  1. don't use echo for arbitrary data
  2. quote your variables

So:

printf '%s\n' "$portis"
  1. Avoid `...`. Use $(...) instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.