Opened 7 years ago

Closed 7 years ago

#9794 closed bug (invalid)

Terminal doesnt like cd'ing in scripts

Reported by: streak Owned by: nobody
Priority: normal Milestone: R1
Component: Applications/Command Line Tools Version: R1/alpha4.1
Keywords: Cc:
Blocked By: Blocking:
Platform: x86

Description

if i create a small script called 'go':

#!/bin/bash
 if (($# ==0))
 then
 basename=`basename "$0"`
 echo  echo "Usage: $basename [predefined directory to go]" 
 echo "eg:    $basename gcc"
 echo "eg:    $basename data'"
 echo  exit
 fi

if [ "$1" = "da" ] || [ "$1" = "data" ] ; then 
echo '[!] going to Data'
cd /Data
exit;  
fi 

and i start it 'go data' or 'go da' Terminal should quick jump into /Data directory [checked on linux.. it works] but on in Haiku Terminal..

Change History (3)

comment:1 by streak, 7 years ago

in Haiku's Terminal this script not work. The script runs correctly but 'cd /Data' command does not change directory to /Data. Of course i have /Data directory :D and typing cd /Data straight in terminal works.

in reply to:  1 comment:2 by siarzhuk, 7 years ago

Component: Applications/TerminalApplications/Command Line Tools
Owner: changed from jackburton to nobody

just have checked on hrev45711

Replying to streak:

in Haiku's Terminal this script not work.

That looks not true. Modify your script as below:

    cd /Data
+ ls -al
    exit; 

and you should see the contents of /Data during run.

The script runs correctly but 'cd /Data' command does not change directory to /Data.

the script is executed in child process and modifies the cwd of the that child process. The cwd of parent process (session of bash running in the Terminal) was not modified. Looks like the bash configuration issue.

comment:3 by bonefish, 7 years ago

Resolution: invalid
Status: newclosed

I don't know what you tried in Linux, but this script is most certainly is not supposed to work as you say. You can do something like this with a shell function, though.

Note: See TracTickets for help on using tickets.