i was presented with a challenge that is beyond my current shell knowledge: how can you have a script that executed interactive will change your current working directory?
Example (under MacOS):
1. start Terminal and my current working directory is my home folder
2. execute a script that, when completed, will change my shell's working directory to something else....
your suggestion does work but it's not quite i had in mind....
I'll provide additional details: let's assume that i want to change the behaviour of built-in ls command, where by typing:
ls folder_name
instead of listing the content of that folder, it will list the content AND change directory to that folder.
If you take the question literally, then no. The shell has to change its own directory, nothing from the outside can force it to change. Any external program will have its own, separate, current directory and changing it won't change the shell's.
You can tell the shell to execute a script internally, though, which is how jim's solution works. The effect of a sourced script is the same as if you'd typed it into your shell.
---------- Post updated at 12:19 PM ---------- Previous update was at 12:16 PM ----------
Quote:
Originally Posted by gigagigosu
I'll provide additional details: let's assume that i want to change the behaviour of built-in ls command, where by typing:
ls folder_name
instead of listing the content of that folder, it will list the content AND change directory to that folder.
there must be a way to do it, isn't it?
"built-in" has a specific meaning in the context of shell languages, and ls is not a built-in. It's an external program. Quite a few things you use in the shell probably aren't built-ins.
If you have bash or ksh, you could do it with a function I suppose:
The [ -d ] part is so it doesn't bother cd-ing into non-folders.
Hello,
I have the following script that just archives and clears some log files.
#!/bin/bash
# script: archive_logs_and_clear
# add date to logfile names and copy archive directory
# clear logs
# change to script directory
cd ... (4 Replies)
when user types "pwd.sh joe" at command line, it generates pwd as abc123 and when user types "pwd.sh jane" at command line, it generates pwd as abc123.
pwd will change every 90 days.
my pwd file will be always abc123 until i change joe/jane/bob pwd manually. (3 Replies)
how can i get the absolute path of whatever directory a script and/or command is in when it is run?
i want to know the directory. say for instance, if i were to run the "who" command, i want to know exaclty where the who command is located.
if a user ran a script, i want to know where there... (2 Replies)
Hi,
I have configured ldap client on openSUSE 11.3 with yast2 config.
Since I am able to get list of all users through getent, it seems configuration done properly.But while logging in with ldap id its prompting for password change.
login as: testuser
Using keyboard-interactive... (1 Reply)
currently, my samba login works just fine. i want my clients to use aix5.3 account to login to samba so they don't have to change samba pwd and aix pwd. i googled, and vi /usr/lib/smb.conf per some of knowledge base, but i could not get to work.
aix5.3 and samba 3.0.24.0
thanks in advace..... (2 Replies)
1. The problem statement, all variables and given/known data:
need to implement mkdir, chdir, mv, pwd
given a shell.cpp directory.cpp and some other files
this shell missing these commands, and i need to implement them inside the shell
2. Relevant commands, code, scripts,... (0 Replies)
Hi,
When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script...
Script:
REM :: File Name : Refresh_OTL.bat
REM :: Parameters : %1 - Region
REM :: : %2 - Cube Type
REM ::... (5 Replies)
Dear All,
Could I change password while login in to ftp server(solaris 10)? I tried to use fileZilla and command prompt(window) to change my password but It can't. Do you have any suggestion ?
Ps. I can't telnet and ssh to the server because of poicy for ftpuser.
Thank in advance (3 Replies)
Here is my script
#!/bin/bash
pwd
cd /var/lib/pgsql
Both "pwd" and "cd" are not executed is there any other way i can change the current working directory to /var/lib/pgsql pls help! (9 Replies)
hi, this echo $SHELL will give the shell name.. how to get the other list of variables (besides SHELL) values?
and also, different shells have different variable names (example SHELL) (10 Replies)