Reputation: 1
Very easy question but I really can't find this when I Google. Sorry! I'm trying to write a script that runs a user's command that he or she enters but I can't run the command that the user enters.
#!/bin/bash
echo -e "Enter a Command: "
read $COMMAND
echo "Output: $COMMAND" # I can't figure how to implement and print the command
Enter a Command: ls Output: folder1 folder2 folder3 test.txt)
Upvotes: 0
Views: 1429
Reputation: 1
Thanks! This answered my question:
#!/bin/bash echo -e "Enter a Command: " read COMMAND echo Output: eval "$COMMAND"
Upvotes: 0
Reputation: 298
All you need is to delete the dollar sign from the read command
#!/bin/bash
echo "Enter a Command: "
read COMMAND
echo "Output: $COMMAND"
Happy scripting!, please don't forget to marked as answered ;)
Upvotes: 1