bash

tilde expansion in environment variable

In my .sh file, I have this, cp $file $SOME_PATH, while $SOME_PATH is exported as export SOME_PATH="~/path/to/path/". But when I ran this .sh file, I got error message saying like * no such "~/path/to/path/" exists.* I replaced ~ as $HOME, then the error was gone. So what's up here with the tilde? Thanks in advance. ...

Simple Mac Bash Script (Find/Replace)

Hey Folks, First, any support and help on this is largely appreciated. I'm trying to write a simple Bash script (completely new to this) to replace a file in a given directory. Basically, I need to write a script to replace the safari preference file, here's what I have..and what's not working for that matter: #!/bin/bash find /Fi...

sudo permission denied

I ran this code: sudo cat <<EOF | sudo sed -e "s,%,$,g" >/etc/init.d/dropbox echo "Hello World" EOF But even though, I get "permission denied", cause you have to be root to make changes in the /etc/init.d directory. And somehow, my command above doesn't work. Is there a way to solve this? ...

"sed" command in bash

Could someone explain this command for me: cat | sed -e 's,%,$,g' | sudo tee /etc/init.d/dropbox << EOF echo "Hello World" EOF What does the "sed" command do? ...

Bash, Perl, or Powershell? For Jobs/General

Despite knowing a good bit of C++......i actually don't know that much about scripting languages. I feel like however I need to learn more about them. However there are a fair bit of different ones, but which one would be the best one to learn for a job? (I am a CS graduate in December btw) or just a general "better" to work with. Power...

i got to clarify what is /bin/sh/ -c !

correct me if i'm wrong its the path location where the shell cmds resist and interpreted as C prog. so that if a cmd is passed it will call that function lokking in /bin/sh plz kindly guide me if im wrong ...

Convert .bat file to .sh file

I have to convert the following .bat code in the .sh code echo Setting Bonita Environment variable set "JAVA_OPTS=%JAVA_OPTS% -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory" set "JAVA_OPTS=%JAVA_OPTS% -Djava.naming.provider.url=jnp://localhost:1099" set "LOG_OPTS= -Djava.util.logging.config.file=D:\jboss-5.0....

How many arguments can I pass to a bash function?

Is the number of arguments that a bash function can accept limited? ...

newbie in bash scripting assistance please

Hi all I run bash scripts from time to time on my servers, I am trying to write a script that monitors log folders and compress log files if folder exceeds defined capacity. I know there are better ways of doing what I am currently trying to do, your suggestions are more than welcome. The script below is throwing an error "unexpected en...

Pretty-print for shell script

I'm looking for something similiar to indent but for (bash) scripts. Console only, no colorizing, etc. Do you know of one ? ...

bash: extract double from string

hello I have this string in bash: str=sdk.iphoneos4.1.sdk and I would like to have a variable with '4.1' in it is there any way to parse a float/double value in bash ? ...

what does this script do?

#!/bin/bash RYD=/share FILESPEC=*.sh DIRPERM=700 FILEPERM=750 OWNER=user:group CH_FSPEC=0 if [ -d $RYD ]; then find $RYD -type d | xargs chmod $DIRPERM if [ $CH_FSPEC -gt 0 ]; then find $RYD -type f | xargs chmod $FILEPERM else find $RYD -type f | grep -v "$FILESPEC" | xargs chmod $FILEPERM fi chown -R $OWNER $RYD for...

Incrementing time (minutes and seconds) in bash / shell script

I need to increment minutes and seconds (in relation to time) in a variable. First, I'm not sure whether declaring a 'time' variable is written as time="00:00:00" or time=$(date +00:00:00)? From there, I want to increment this variable by 10 minutes and seconds resulting in 01:00:00 increased to 01:10:10 to 01:20:20 etc (all t...

bash navigating to the earliest/latest command in history when you're in the middle of your history

Say I am in a bash terminal and have a large history of commands. I pressed the up arrow a whole bunch of times and am in the "middle" of the history. I want to now navigate to the first or the last command in my history quickly (without holding down the up or the down arrow for a long time). Is this possible? If so, what is the shortcut...

Copy the three newest files under one directory (recursively) to another specified directory

I'm using bash. Suppose I have a log file directory /var/myprogram/logs/. Under this directory I have many sub-directories and sub-sub-directories that include different types of log files from my program. I'd like to find the three newest files (modified most recently), whose name starts with 2010, under /var/myprogram/logs/, regardl...

Bash: Finally (Try, Except) Exception

I want to execute some commands on the end of the bash script, even if the user press CTRL+C to cancel its execution. I know I can run the bash script from inside another programming language (for example, Python), so that I can use the 'finally' (try-finally) block to execute some code. But knowing that StackOverflow is a center for e...

To read from file and putting values in WHERE clause via shell script

Hello, Shell Script #! /bin/bash sqlplus -s <username>/<passwd>@dbname << EOF set echo on set pagesize 0 set verify off set lines 32000 set trimspool on set feedback off SELECT * FROM <dbname>.<tablename1> tr LEFT JOIN <tablename2> t2 ON t2.id2 = tr.id1 LEFT JOIN <tablename3> t3 ON t3.id2 = tr.id1 LEFT JOIN <tablename4> t4 O...

How to read lines from file, storing it and again start from the last stored line in UNIX

Hello, The shell script needs to read batch of lines (lets say first 150). then storing that values in variable. After the execution of the SQL, now it should read from 151 to 300. In this way, it will read lines in batch of 150 and storing it in a variable till 32000 lines are read. Script Looks Like #!/bin/bash t2val=$(cat...

Unix script to find all folders in the directory

Basically I need to run a Unix script to find all folders in the directory /fss/fin, if it exists; then I have tar it and move to another directory /fs/fi. This is my command so far: find /fss/fin -type d -name "essbase" -print Here I have mentioned folder name essbase instead of that I have to find all the folder in the /fss/fin. ...

Passing second argument onwards from a shell script to Java

If I pass any number of arguments to a shell script that invokes a Java program internally, how can I pass second argument onwards to the Java program except the first? ./my_script.sh a b c d .... #my_script.sh ... java MyApp b c d ... Thanks, ...