Tag Info

Hot answers tagged

26

Assuming the commands succeeded, /var/log/messages and /var/log/wtmp still exist but are now blank. Shell Redirection > is a redirection operator, implemented by the shell. Its syntax is: command > file This redirects command's standard output to file. file may also be a device node. If file doesn't exist, it is created as a regular file. If file ...


15

cat will list the contents of a file comming after cat to standard output and the > sends it to the file messages and wtmp where > means to first remove all contents of the file and >> would mean to ADD to the current file. In this case you are using > so the file will end up being empty. Now for the kicker: /dev/null is a device that sends 'nothing' to ...


10

Use builtin command source (from help -m source): source - Execute commands from a file in the current shell. Example of execution mentioned in Question: pandya@pandya-desktop:~$ source ch_dir pandya@pandya-desktop:/usr$ Here you can see cd /usr is executed in current shell and hence directory of current shell changed! Hope this will help to ...


9

As already answered, these two lines are clearing the content of the /var/log/messages and /var/log/wtmp files, or are creating them in the unlikely event they do not already exist. However, they are based on a well established urban legend that gives /dev/null "paranormal" powers. It actually has none so cat /dev/null is a waste of keystrokes, time and ...


7

There are two errors. In short, this is the particular fix I would suggest (details follow): #!/bin/sh UBUNTU_MENUPROXY=0 /home/andrea/Programmi/Aptana_Studio_3/AptanaStudio3 Bad Hashbang Line As Shutupsquare says, your hashbang line (technical details) should start with a #! rather than just !. That is causing the first of your two error messages, and ...


7

First && means execute the command which follows only if the command which preceded reports success (exit code zero). The [ is a test command. [ -n "$T_R" ] means return success if the shell variable T_R is not empty. The ! in [ ! -n "$T_R" ] negates the test so that success if reported only if the variable T_R is undefined or empty. If T_R is ...


6

The problem is that you're trying to reference a variable called $ibhav (not $i). Variables can be more than one character, and in your example, the shell has no way to tell if you meant $i or $ibhav (or $ibha or $ibh or $ib). The fix is to bracket your variable names: echo "${d}${m}${i}bhav.csv.zip" so that it's unambigious which variable you're ...


5

> is output redirecting operator. It will redirect the output of command to file mentioned after it instead of standard output device, truncating or overwriting file's contents. for example ls -l > demo.txt. After executing this command, "demo.txt" will contain th output ls -l command. Now next thing is what is this /dev/null./dev/null is the null ...


5

Just run the script with a . like this: pandya@pandya-desktop:~$ . ./ch_dir


4

No it isn't. As you said, man sim doesn't exist. And running sim gives No command 'sim' found, but there are 23 similar ones In your example 'sim' was only used as part of a file name. 'fun-sym' could have been almost anything, it has no effect on the command. Since it is only the file you are creating, it only has to be a valid file name. All that ...


4

Apparently one of your modifications to .bashrc introduced an error that treats /bin like something other than a directory (for example, by trying to run it as an executable file, read data from or write data to it as a file, etc.). Because .bashrc runs when your interactive shell starts, the error message always appears. You may be able to identify the ...


4

Use magic. If you're low on magic, try passing apt-get some arguments. -y should help you out. It tells apt-get in advance that you're going to say yes to the confirmation prompt. apt-get install -y docky geany firefox audacity kdenlive openshot shotwell stellarium thunderbird For a list of what you can and can't do with apt-get, type man apt-get in a ...


4

You can use the join command join -t ":" username contacts username file has the format user1:id1 user2:id2 contacts has the format user1:contact1 user2:contact2 When the file is not sorted then you can do the following sort -b username > username.sorted sort -b contacts > contacts.sorted and then run the join command on username.sorted and ...


4

In a python script: A pragmatic solution In case it is a "one time job", specific for one situation, the following works: #!/usr/bin/env python3 with open(file1) as names: names = sorted(names.readlines()) with open(file2) as data: data = data.readlines() for i in names: item = i.replace("\n", "")+str([d[d.find(":"):].replace("\n", "") for d ...


3

With process substitution in bash, we can make a very compact variant of the join solution even for unsorted input files: join -t: <(sort user-name) <(sort user-details) The output is just like the example output in the question: Neeraj:149:neeraj@xyz.com Rahul:148:rahul@gmail.com Tarun:143:tarun@gmail.com We are using the first field/column of ...


3

Couldn't you simply run it in the background, inside a while loop: while true do [command] sleep [number of seconds] done So the construction would be: Add a line in /etc/rc.local to call your script (your ShellScript.sh) + "&" to make it exit Run the commands you want the ShellScript.sh to execute in a while loop (inside Shellscript.sh): ...


3

Should be #!/bin/bash. I also think that you should have a newline at the end of export UBUNTU_MENUPROXY=0. #!/bin/bash export UBUNTU_MENUPROXY=0 /home/andrea/Programmi/Aptana_Studio_3/AptanaStudio3


2

Here's an awk solution: $ awk -F: -v OFS=: 'NR==FNR{a[$1]=$2; next}{print $1,a[$1],$2}' user-name user-details Tarun:143:tarun@gmail.com Neeraj:149:neeraj@xyz.com Rahul:148:rahul@gmail.com Explanation -F: : sets the field separator to :. -v OFS=: : sets the output field separator (OFS) to : for pretty printing. NR==FNR : NR is the current line number ...


2

There is no relation at all between "echo" in bash and "echo" in PHP. They just happen to share the same keyword for the same action, they do not depend on each other. Often times the design of some languages influences another languages, and those that design new languages features often took inluence from existing languages. These are why many languages ...


2

They don't. The codebase behind the runtime environments and libraries may use shell scripts as glue, but runtimes of languages like JavaScript and PHP don't depend on them. The use of commands like echo and printf are indicators of the languages the creators were influenced by, such as C and shell. This also holds true for compiled languages. Step back for ...


2

Try putting them in a script and adding that script as the entry in your Startup Applications. It's hard enough to use environment variables and ~ in desktop files, let alone full-fledged command substitution, as evinced by Desktop Files don't use seem to use $PATH correctly and How to include environment Variable in launcher for icon.


2

Turns out each entry on the Startup Applications list gets created as a .desktop file on ~/.config/autostart$. As mentioned by both @muru's answer and an answer on the question he linked, .desktop files don't expand the tilde as the shell would. Neither they seem to have the ${HOME} variable. So the solution was to add the following line to the ...


1

You shouldn't be using []: Go for this (with the (()) brackets: a=2 b=3 c=$((a+b)) echo 'The result is:' $c returns: The result is: 5


1

You can simply list multiple packages to install in the same command. I believe this will also give you only one y/n prompt. Example: sudo apt-get install docky geany firefox


1

Just use if (! -d /folder ) then #run some code here, if the folder does not exist


1

For that particular while loop (using getopts) you would usually put it in a shell script and then call the script with your options/argument(s) e.g. #!/bin/bash while getopts "f:t:d:g:o:p:b:q:r:" opt; do case "$opt" in f) fan=${OPTARG} ;; t) echo "doing somthing with option t = $OPTARG" ;; esac done shift $(( OPTIND - 1 )); then make it ...


1

Try with my code: First sort both user-name and contacts and write the output into one file named user-name_contacts with this: sort user-name contacts > user-name_contacts Next, run this command to join two files: sed -i '/$/N ; s/\n\(.*\):/:/' user-name_contacts Output: Neeraj:149:neeraj@xyz.com Rahul:148:rahul@gmail.com ...


1

Just make an infinite while loop: #!/bin/sh while [ TRUE ]; do check_server_status 10.0.. etherwake ff:ff.. done


1

How about while server-is-not-running; do try-and-start-server sleep seconds-to-wait done where server-is-not-running is your current test to see if the server is running, i.e. a shell function or an external command returning non-zero if the server is running (alternatively, ! server-is-running if that function or command returns zero if the ...


1

Ok, I think I knew that. You want to check the battery status in every X interval of time. It's easiest way that you run it in the background, inside a while loop: while true do # Any script or command sleep [number of seconds] done And if you want to run the script on startup and from then on every 5 minutes, so the construction would be: Add ...



Only top voted, non community-wiki answers of a minimum length are eligible