Command doesn't execute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command doesn't execute
# 1  
Old 02-06-2011
Command doesn't execute

Hi All.

Little mystery here. I've been teaching myself perl, and I want to execute regular linux / unix commands i.e. cd .. , cd /etc and have been using the command(s)

execute ("cd ..");
or
system ("cd ..");

I don't get any error messages, even when I do a debug, but for some reason even this doesn't work.

Here is the super-simple code I am using:

Quote:
#!/usr/local/bin/perl
#
# Program to do the obvious
#

print "\n\n";
print 'Hello world.'; # Print a message
print "\n\n";

execute ("cd ..");
execute ("cd /etc");
What am I doing wrong?

Regards
# 2  
Old 02-06-2011
There is a problem with these lines:

Quote:
execute ("cd ..");
execute ("cd /etc");

What do you expect the lines to do? What output do you anticipate, and what output did you receive?

We cannot guess what a faulty command is intended to do.
# 3  
Old 02-06-2011
Hi.

The commands are quite simply expected, by myself, to change the directory up one level, then change the directory to the /etc directory.

I get no results from either command shown by a changed directory.

This code:

Quote:
#!/usr/local/bin/perl
#
# Program to do the obvious
#

print "\n\n";
print 'Hello world.'; # Print a message
print "\n\n";

exec ("cd ..");
exec ("ls -l");
exec ("cd /etc");
gives this result

Quote:
winterbolt@Winterbolt:~/Desktop$ perl helloworld.pl


Hello world.

total 8
-rwxrwxrwx 1 winterbolt winterbolt 179 2011-02-06 20:58 helloworld.pl
-rw-r--r-- 1 winterbolt winterbolt 343 2011-01-23 14:05 important notes
winterbolt@Winterbolt:~/Desktop$
The directory does not change...

Regards
# 4  
Old 02-06-2011
exec will replace the current process with the command which you executed.And if a shell script changes the working directory,the parent shell(process) won't be affected.
# 5  
Old 02-07-2011
Ok.

So if that is the case, then how do I execute multiple commands in a row?

Smilie

Regards
# 6  
Old 02-07-2011
Every command shown in your script can be achieved with a simple Shell script and does not need Perl. No sure what you want to achieve here. Maybe you need to sort out the "cd" commands in Shell, then call the Perl script from the Shell script?

To answer you question properly, please look at the Perl "chdir" command.
http://www.perlhowto.com/system
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. Homework & Coursework Questions

Command Doesn't Show Description

im making c code in linux and im having problems with one command, id should bring up a list but instead id doesnt do nothing, there are no error's, can anyone solve whats wrong ? void environ() { extern char **environ; int i=0; for (i = 0; environ !=NULL;i++) { ... (1 Reply)
Discussion started by: figureout
1 Replies

5. Shell Programming and Scripting

crontab doesn't allow `command` ??

Dear All, We wrote a script to clean email mailbox when they're nearly full and put it in cron : 0 0 * * * /root/quota/autoclean.sh > /root/quota/autoclean.`date '+%Y%m%d'` 2>&1 I've run this command from command prompt, it did work. However, if running from cron, it returned such error... (1 Reply)
Discussion started by: tiger2000
1 Replies

6. Shell Programming and Scripting

cd command doesn't work through variables

Hi.... cd command is not working when dual string drive/volume name is passed to cd through variables....... For Ex.... y=/Volumes/Backup\ vipin/ cd $y the above command gives error....... anyone with a genuine solution ? (16 Replies)
Discussion started by: vipinchauhan222
16 Replies

7. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies

8. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies

9. Shell Programming and Scripting

Command doesn't work under cron ?

I have defined in cron crontab -l >/FIXENGINE/data/crontab.$(whoami).$(date +%a) The resulting file is named crontab.fixadmin. When I run the above from a command line, the file is named: crontab.fixadmin.Tue (or whatever day I happen to be running) The question is - why do I get... (4 Replies)
Discussion started by: bigjohn-nj
4 Replies

10. Shell Programming and Scripting

Doesn't recognize the mv command

I'm nearly finished my program i've got everything in place and than when i run it it comes back with the reply mv: command not found. This is the code that seems to be causing the problem. elif then echo "There are more than one '$1' files in the system." echo "Please... (2 Replies)
Discussion started by: zoolz
2 Replies
Login or Register to Ask a Question