Source Command in Unix


 
Thread Tools Search this Thread
Top Forums Programming Source Command in Unix
# 1  
Old 09-26-2011
Source Command in Unix

Hi all,

I am having two files, the content of first file (out.bash) is
Code:
#!/bin/bash
 
cd /home/jessy/abc
echo "hihi-part1"

Second file content (out2.csh)is
Code:
#!/usr/bin/csh
source ./out.bash
echo "hihi-part2"

When I run in Ubuntu, i am typing bash out2.csh,
the output display is
Code:
 hihi-part1
                               hihi-part2

I am just wondering why my current directory is not changed to /home/jessy/abc path?

2. If i am running the script from command prompt like
Code:
source ./out.bash

, my path will be changed to /home/jessy/abc

3. What is the "start" equivalent command in Linux? I wish it can work like WIN dos's start command so that it can direct the folder to the path that I have specified.

Thanks.
# 2  
Old 09-26-2011
ad 1: It's not changing the path because the cd is run in the context of the shell script process, which does not influence the interactive shell process.
ad 2: See above. If you manually source the file, its commands are run in the context of the current shell, thus the path change
ad 3: Huh?

Generally: please start using [CODE] tags for script listings and similar.
# 3  
Old 09-26-2011
That means I don't have any method that can call a script file to change my directory? In Win DOS, we can write a bash file, for example like abc.cmd where abc.cmd will change my directory , for instance from c:\jessy\jessy2 to c:\jessy. We can just simply call abc.cmd in order to to the task?

2. In Win, as long as I set my environment path, I can easily run abc.cmd in whatever directory I am in? How about in Linux, is there any environment path for me to set up so that I can run my shell file irregardless of my path?

3. Regarding the start command, for example, my current path in my command prompt is C:\Document_and_Setting, when i run start. command, it will open a new window for me and I can easily access the files which are stored under C:\Document_and_Setting.

4. Is Linux having this command? set DISPLAY jessy:0.0? I am just wondering why I can't run this command in my Linux?

5. Is Linux having WIN's equivalent command - title ? I wish to change title for every different console?

Thanks. Sorry I am indeed very newbie in Linux.
Thanks.
# 4  
Old 09-26-2011
  1. Not with a shell script. That's what aliases, functions, etc.. are for, eg. alias goproj="cd ~/projects"
    Put that in your .bash_profile (if you're using bash). Don't know the equivalent for (t)csh.
  2. Same. Take a look at $PATH
  3. Is it opening a file manager window, or a new command line window? For the former, that would depend on your WM. For the later, xterm& should work in any WM.
  4. That's (t)csh syntax, and won't work with bash, ksh, or zsh. The appropriate command for those is export DISPLAY=jessy:0.0
  5. No special command for that. Some terminal emulators support the use of ANSI control characters for that, but it's not guaranteed. This has been discussed before, so please search the forums for more information

Last edited by pludi; 09-26-2011 at 11:11 AM..
# 5  
Old 09-27-2011
Thanks for the reply.
I had tried for 1,2. It works. Thanks.
For 3, start. in WIN will start a new file manager window.
For 4, I am not that sure for this. However, I will have a look at what your suggestion is. I need to correct my previous command, it is setenv DISPLAY jessy:0.0.
For 5, ok. Noted. I will browse through it.
By the way, what does it mean by ./ ? I always encounter this like source ./abc.bash and ~/path ?
Thanks.
# 6  
Old 09-27-2011
How to start a new instance ("new window") of the file manager depends on your WM, and what file manager is used. Could you post that information?

set variable value and setenv variable value are both (t)csh syntax. You can use the alternative I've given in both instances.

./ means "use the current directory". As a safety precaution the PATH variable in Unix doesn't usually include the current directory, unlike Windows. So to run a program or script from the current dir, one has to explicitly state that. That way it's harder for someone to plant a malicious program called (for example) ls.
~, when used in a path, is shorthand for the current users home directory.
# 7  
Old 09-29-2011
For the .start or start command in WIN, I am not sure whether I had described wrongly or not. It will start a new window explorer.

For the set in Linux, what does this mean?
Code:
set cwd = $home - LIne 1
alias cd            'cd \!*; echo $cwd' - Line 2

I have two doubts here,
a. Is the $cwd in Line 2 refer to the same as in Line 1?
b. In Line 2, what does the cd \!* means? !*

Thanks very much.

Last edited by pludi; 09-30-2011 at 03:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Fedora

Is UNIX an open source OS ?

Hi everyone, I know the following questions are noobish questions but I am asking them because I am confused about the basics of history behind UNIX and LINUX. Ok onto business, my questions are-: Was/Is UNIX ever an open source operating system ? If UNIX was... (21 Replies)
Discussion started by: sreyan32
21 Replies

2. Shell Programming and Scripting

Ps command source.

Dear friends, I am using SCO Openserver 5.0.7. Where does the ps -ef command pick the information from? Is it stored in some file? Also, the ps -ef command or the ps -eo args command displays truncated information. How to get the complete expanded output without truncation? Thanks in... (8 Replies)
Discussion started by: sabu
8 Replies

3. Shell Programming and Scripting

Source Command

Hello, I have created a script that changes directories but in order for it to work I always need to invoke a source ./script Here is a copy of my script.. if I do not invoke "source ./script" the change directory command does not work. Any ideas? // The script is pretty basic ... (1 Reply)
Discussion started by: NelsonC
1 Replies

4. UNIX for Dummies Questions & Answers

Where can i get unix source code?

Sir please tell me where can i get source code for some unix kernal and shell also. (1 Reply)
Discussion started by: VIPUL15
1 Replies

5. Post Here to Contact Site Administrators and Moderators

Source Code Of Unix

Do you have the source code of UNIX? If yes, can you please send it to me on my email email address deleted For your this help I shall be obliged to you. With Regards rajesh ***phone removed*** (1 Reply)
Discussion started by: rajesh_ranjan26
1 Replies

6. Post Here to Contact Site Administrators and Moderators

the source code of unix

tha ithela na moy peite an mporo apo kapoy na vro ton pigaio kvdika toy unix se glossa c .efxaristo. (1 Reply)
Discussion started by: matsoyka
1 Replies

7. Shell Programming and Scripting

problem with source command

Ive written a script that uses the source command but i get the error: source: not found when i enter it myself manually it works fine, is there any reason I cannot use this command in a script? (2 Replies)
Discussion started by: jonbyrne123
2 Replies

8. Programming

ls command source code

Hi all, I want to know how ls was implemented in linux.; How to view the source code? filename/sitename...? thanks (1 Reply)
Discussion started by: linuxer_rh
1 Replies

9. Programming

UNIX source?

Where can one download the UNIX source code? Thx (9 Replies)
Discussion started by: Sharkbait
9 Replies

10. Shell Programming and Scripting

UNIX commands source

does anyone knows where i can find the source code any Unix commands??? THx (1 Reply)
Discussion started by: rubis450
1 Replies
Login or Register to Ask a Question