I am trying all sorts of combinations to do pattern matching using tcsh (cannot avoid tcsh). I runa command and then parse (using space) it. It works well. However, it doesnt do pattern match when I want to get a number from it.
It never goes inside if loop to give me "loop" output.
echo "Command: $command\n"
set tg_activity = `$command`
foreach abc (`echo $tg_activity`)
echo "The part is: $abc"
if ( "$abc" =~ ^[0-9]* ) then
echo "loop"
set job_id = "$abc"
break
endif
echo "No If\n"
end
If i use $abc instead of "$abc" inside if condition, it gives me error"if: Missing file name.". "$abc" works well here as it does pattern matching with any (*) and gives "loop" output. The problem is in the condition statement (narrowed down). How can I pattern match here. Please advise
foreach elem ($tg_activity:q) if ($elem:q =~ [0-9]*[0-9]?) then set job_id = echo $elem:q
break endif end
Above worked for me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.