Software :: Export A Variable To Parent Shell In Shell Scripting?

May 21, 2009

Is there a way to export a variable to parent shell in shell scripting ?

View 3 Replies


ADVERTISEMENT

Software :: Bash Shell - Export A Variable From A Script?

Jun 24, 2010

I need to be able to set a variable that is used by my build environment. I need to be able to change this variable "on the fly" as I work with multiple build environments. A portion of the variable is arbitrary, so I need to treat the arbitrary portion of the variable as an argument.

I would normally just create an alias, but BASH doesn't support arguments to aliases. So the workaround for the no-alias-arguments bug is to use a script. No problem. Except the variable I set in the script does not exist when I exit the script.Now, if I run the script by using "$ . myscript" it works in that the variable is set after it exits. The problem is the argument checking I have in the script doesn't work anymore. BASH aliases don't support arguments and I can't export a variable from a script unless I source the script (is it even a script at that point?) Maybe I am simply taking the wrong approach.

View 2 Replies View Related

Programming :: Shell Scripting / Create A Shell Script Similar To Ls?

Jun 5, 2011

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.

Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....

View 10 Replies View Related

OpenSUSE :: Export Variable In Subshell Back Out To Parent?

Apr 29, 2011

Is there any way to use "export" inside a bash script that will affect the variable in the parent process (i.e. the terminal where the script was run)?

View 5 Replies View Related

Programming :: Communicating From Subshell To Parent Shell

Mar 17, 2010

I am stuck at a issue in shell scripting. I had tried all the possible ways, yet unable to reach a solutions. I am working on a application, which runs on C shell. For this I had created a installation script, which installs my application in the system, it is working fine. Now, the problematic part is that I had set an alias in ".cshrc" file, which invokes my application when any user types it. But for an alias to take effect, I need to re-login into the system, because I have to read ".cshrc" file again, in order to take effect of my alias. However I can use "source ~/.cshrc" file after my installation, so that my aliasing works without logging back again. But Requirement is that, just after installing the application, alias should be available to user, without logging back again and without issuing any extra command.

I had tried one other way is that, I had created a symbolic link in ~/bin directory, which points to my application to be run, but even that require, to issue rehash command in order to modify internal command hash table. So, my overall problem is that changing alias in subshell should be reflected to parent shell,without running any other command (all commands should be run in installation script only). Or, in other way how to rehash parent shell from subshell. The ultimate requirement is that,the command that will run my application, should be available just after executing the installation script, either by aliasing or by rehashing, or by any other means.

View 9 Replies View Related

General :: Show Only The Parent Folder In The Shell Prompt?

Aug 8, 2011

Whenever I go inside a directory in Linux, it shows the file path at prompt like:

root@vivek-HP-Pavilion-dv6-Notebook-PC:/var/www/abc/def/

How can I change it to show short names instead?

View 1 Replies View Related

Software :: Nested Shell - Disown Job Not Found (Parent Or Child)

Jun 1, 2011

I'm in a nested shell trying to use disown to re-root myself as well as a child. Looks like this:

Code:
# echo $$
1234
# disown 1234
disown: job not found: 1234
# disown $$
disown: job not found: 1234
# pgrep mychild
2222
# disown 2222
disown: job not found: 2222

This is in zsh. The goal is to have process 1 (the root of all processes) to become the parent.

View 3 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

Ubuntu :: Sed And Shell Scripting ?

Feb 22, 2010

I have recently put together an install script to make my life a little easier.

The server is using lighttpd and I wish for the auth mod to be enabled.

For the line:

I require the script to call the servers external IP and insert it in place of 127.0.0.1

View 5 Replies View Related

General :: What Is Shell Scripting?

Feb 15, 2011

What is shell scripting? what is 'bash'?

View 14 Replies View Related

Programming :: Shell Script To Automatically Delete Files With The Same Name As The Parent Directory?

Mar 18, 2010

I am facing a problem in Windows due to a virus called Newfolder.exe which creats files with the same name as it's parent directory and an extension .exe and this happens for every directory in the entire hierarchy in the infected pen drive. The antivirus detects them, but is sucking slow. So I thought this is a good opportunity to use the concepts of the all mighty shell script to remove those as they follow the same pattern. Say my complete path is

Code:

/home/pkd/fol1/

The virus would have created an file with complete paths

Quote:

/home/pkd/fol1.exe

If fol1 has two more directories fol11 and fol12 Then there would be two more .exe(virus created) in the following path

Quote:

/home/pkd/fol11/fol11.exe
/home/pkd/fol12/fol12.exe

View 1 Replies View Related

Fedora :: Getting 0 For Both Conditions In Shell Scripting?

Jun 8, 2011

#!/bin/bash
str3=""
if [ -z $str3 ] ; then
echo " $? = $? "
fi

[code]....

output:-

$? = 0
$? = 0

why we get 0 for both conditions? I am using FC15.

View 1 Replies View Related

General :: Any Projects On Shell Scripting?

Dec 6, 2010

Just give me any project on shell scripting .. to start working on it and practice my self ..

View 2 Replies View Related

General :: First Line In Shell Scripting?

Feb 15, 2011

I am a bit confused with the first line while writing a shell script , if someone can please explain me the meaning of the first line " #!/bin/bash "the confusion for me is the # at the beginning , in shell scripting # means a comment. but in this case it loads the shell which the script must use,instead of commenting the line how is this possible. where is this defined , any particular file.

View 3 Replies View Related

General :: Finding A Recursive Shell Or Perl Script To Delete Files With The Same Name As The Parent Folder?

Jun 29, 2010

is there a recursive shell or Perl script to delete files with the same name as the parent folder? i wish to include the starting folder name as argument to the script.

View 2 Replies View Related

Ubuntu :: Shell Scripting Command Doubt?

Jan 1, 2011

How do i find out if a particular item is a file or a folder through the terminal ls -la gives 'd' before the permissions for every folder and '-' before every fileLike i want to write a script that backup data if it is a folder and deletes if it is a file

View 2 Replies View Related

General :: Global Expressions Using Vi And Shell Scripting?

Jul 29, 2010

I am trying to learn more about global expressions and how it is needed in changing stuff in vi and in shell scipting in general.My question is basic:

How can I add a " # " pound sign at the beginning of every line in a file. So if I want to remark out every line in a file, what would be the global expression for that? Is there a global expression cheat sheet?

View 4 Replies View Related

General :: Shell Scripting - For Each File In Directory

May 2, 2011

I am working on some homework, however i am not here to be spoon fed. I am trying to get the numerical modification date of each file in a folder. Ie lets say there is a file called bob and it was modified 2006-11-23. i want to get it into a variable as 20061123.

Now i currently have this code:

Code:

However for some reason my output is:

Quote:

See how the 2011 has been placed next to it? i ran it with -x and saw this:

Code:

However i do not know how to find a way around this?

View 11 Replies View Related

General :: Bash Shell Scripting Request?

Feb 27, 2011

I am working on a simple script that should take two command line arguments, a [number] and a [name]. The first thing the script should do is check to make sure that no more and no less than two command line arguments have been entered when calling the script - an error message should be delivered if the condition is not true.

If two args have been entered, then the message 'processing "scriptname"' should appear, where scriptname is the name of the script being called. The script should then write to the screen "Hi [name]!", and should write this phrase [number] of times. For example, the command $ myscript 2 joe would produce the output: I have read the manual many times looking for examples, and I am very close by virtue of my own efforts. Further, I have searched these forums and others for good examples, which have also gotten me very close. Still my script is not completing the objective, and I am wondering if someone could point me in the right direction. Script:

[Code]...

View 13 Replies View Related

General :: Learn Shell Scripting And Came Up With A Lil First Script?

Jan 26, 2011

I am trying to learn shell scripting and came up with a lil first script that I could actually use.I have a basic shell script and all it does is run:

sudo apt-get update
sudo apt-get upgrade

So basically just a shell script that updates your packages. NOW, my question. I made another shell script that makse a bit of a menu and asks what you wanna do, 1 to UPDATE or 2, to CLOSE. How do I make it so when they enter 1 it runs my update.sh ?

View 6 Replies View Related

Server :: Dos2unix Command In Shell Scripting?

Jul 5, 2011

I am new to shell scripting..I really need ur help or guidance here..I have a text file where i have to use dos2unix command.

Now the problem is how do i pass dos2unix command in the shell scripting after it had read the text file ??
And give out the new text file.

View 3 Replies View Related

Server :: Shell Scripting For Launching A Simulation Job?

Jun 27, 2011

I've been doing Finite Element simulations with the Ansys software for several years now, and recently I have been allowed to use a cluster running on Linux (it's a Sun Grid Engine, or SGE). Since I am quite newbie to this thing, I have read a lot on the internet to get more familiar with the Unix language. I found some example codes which are supposed to launch Ansys and read input files, but it does not work for me. Actually, what I want to do is simple:

1- I need to use Ansys 12.1 in batch mode, with the Academic Research license (which is called "aa_r");

2- The software should then read my input file (which is an APDL command file (in case you are familiar with it..)) and save the database and results in my working directory on the server.

The software is located in the following path:

/ansys_inc/v121/ansys/bin/ansys121

My working directory:

/home/myusername/

From what I've found on the web, I have to write a shell script that calls the software and specifies the details (batch mode, license name, input file, ...). Then I have to call this script by using the command "qsub".

Script: myjob.sh

Code:

#!/bin/bash
nohup /ansys_inc/v121/ansys/bin/ansys121 -b nolist -p aa_r -j jobname -i jobname.inp -o jobname.out 2>&1 &

View 5 Replies View Related

Software :: Reading Files In Shell Scripting?

Oct 25, 2010

I am trying to read the fields of a file and manipulate them, record by record. Lets say using awk :

awk -F":" `{print $1 $2 $3 $4 $5}' TrackMsgFile.0806`

This prints my fields on screen.But I dont want to print these fields while reading the records instead store them in some variable and manipulate them as per my logic. Does "awk" or some other shell command provides something for this ?

View 14 Replies View Related

Programming :: Shell Scripting Array - Bad Substitution

Jun 19, 2009

I made a little rsync script for log transfer.

Code:
SERVERS=(SERVER1 SERVER2 SERVER3)
SERVER1_SERV=(web ftp mail)
SERVER2_SERV=(web transcoding)
SERVER3_SERV=(web ftp mail)
for SERVER in ${SERVERS[@]}
do
echo "Starting tranfer for server $SERVER"
for SERVICE in ${$SERVER_$SERVICE[@]}
do
something_to_be_done
fi
done
But when I run it I get ${$SERVER_$SERVICE[@]}: bad substitution

View 5 Replies View Related

Programming :: Shell Scripting: How To Create A User

Sep 5, 2010

How do I create a user account in a shell script? I know this may sound n00bish to you, but I know it's more than just mkdir-ing the home directory and subdirectories.

View 7 Replies View Related

Programming :: Convert String Into An Integre In Shell Scripting?

Dec 2, 2010

I need to part a string into separate integers ....like "0x0-0xffffffff,0x20000" into 3 integers 0x0 and 0xfffffff and 0x20000.... i can't use any other high-level languages ..

View 3 Replies View Related

General :: Incrementing Array Element In Shell Scripting

Jun 23, 2010

ch[1]=0; ch[2]=0; ch[3]=0; ch[4]=0; ch[5]=0; ch[6]=0; ch[7]=0; ch[8]=0; ch[9]=0; ch[10]=0;ch[11]=0; ch[12]=0; ch[13]=0; ch[14]=0; ch[15]=0 ch[16]=0; ch[17]=0; ch[18]=0; ch[19]=10; ch[20]=0;

I have an array ch and I want to increment each element in my array for the following if statement. I'm not sure I have the right array increment syntax but I have tried it in different ways ant it doesn't seem to work.

I tried ch[$1]++, ch[$1]+1, ch[$1++], ch[$1]+=1, ch[$1]=ch[$1]+1 none of these seem to work.
# while loop reading from read.txt for check list 1 - 15
for i in `seq 15`
do
a=`grep "${cl[$i]}" $file`
status=$?
if [[ $status = 0 ]];
then
echo -n -e "1 "
let ch[$i+1]
let k++
else
echo -n -e "0 "
fi
done
for l in `seq 20`
do
echo -n -e "${ch[$l]} "
done

View 2 Replies View Related

General :: Write Either PYTHON Or Bash Shell Scripting?

Jun 4, 2010

I do not know how to write either PYTHON or Bash Shell Scripting. I am to learn one for Linux Administration purpose. Which one will you recommend for a Linux Admin/Eng environment?

View 4 Replies View Related

General :: Randomly Select Folder Using Shell Scripting

Jun 17, 2011

There are five folders in a folder and I want to select one randomly. I used this command:

Code:
rand1="${loc[RANDOM % ${#loc[@]}]}"

but it selects files too. I have no idea about this code even. I found it on a forum.

View 7 Replies View Related

General :: Shell Scripting Text File Creation ?

Feb 16, 2011

I'm just starting out with shell-scripting, but having a problem with making new text files with the touch or cat > commands.

What I've been doing is touch testfile1.txt

Also, I've tried cat > testfile1.txt (text)

Console reports "bash: text1.txt: No such file or directory. Consfusingly, it works fine in the home-directory. But if I move the file to where I want it, I can no longer view, edit, etc. it.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved