From: Robert Klemme Date: 2009-01-08T07:19:48+09:00 Subject: Re: Multiple commands in shell On 07.01.2009 19:08, dusty wrote: > On Jan 7, 11:14 am, Gu stav wrote: >> I'm trying to run multiple commands in the shell from ruby but I can't >> seem to grasp how I keep the "state" from the previous shell command. >> >> For example, how would I perform the following sequence of commands in >> ruby: >> >> 1. cd /dir >> 2. ls >> >> Not counting "ls /dir" that is ;) >> >> I've tried using: >> >> system "cd /dir" >> system "ls" >> >> .but it doesn't work. >> >> Thanks! >> -- >> Posted viahttp://www.ruby-forum.com/. > > > [dusty@dustylaptop:~] $ pwd > /Users/dusty > [dusty@dustylaptop:~] $ ls tmp/ > test.txt > > irb(main):003:0> system('pwd; cd tmp; ls') > /Users/dusty > test.txt > => true Here's another way to do it using a here document by having multiple commands on separate lines - much the same way as in a shell script: robert@fussel ~ $ ruby /tmp/x.rb + pwd /cygdrive/c/Dokumente und Einstellungen/robert + cd /tmp + pwd /tmp + ls x.rb robert@fussel ~ $ cat /tmp/x.rb system <