##MYSQL QUERY##
variable=$(
mysql -sN -u username --password=password << eof use databasename; SELECT id FROM tablename; eof)
variable=$(
mysql -sN -u username --password=password << eof use databasename; SELECT id FROM tablename; eof)
It is possible to alter a variable using parameter substitution as follows :
variable=${variable#id}
variable=${variable#*$'\n'}
variable="${x//$'id\n'}"
The 1st just removes the string "id", the 2nd removes everything up to the first new line and the 3rd removes all instances of the string "id" +newline. As suggested at Linux Questionsvariable=${variable#*$'\n'}
variable="${x//$'id\n'}"
When returning the results in a for loop, the -n parameter for echo, removes the new line that is otherwise there.
##for each##
for ARG in $variable
do
echo -n $ARG
done
No comments:
Post a Comment