Skip to content

Tag: shell

How to append a column for the result set in shell script

I need a script for the below scenario. I am very new to shell script. the above query results with following result Now I need to get result as follows: 1st column, 3rd column ,4th column of above result set and new column with default values Here the last column values is always known values i.e for file1 D…

Running a shell script for a certain duration

I want to be able to run a script on Linux shell (bash) for a certain duration and sleep for a different duration. I’ve written something like the following snippet. However, I see only the sleep happening correctly but the execution stops after first execution. The response I get is ./script.sh: line 3…

I’m getting errors in my shell script

MY CODE : THE ERRORS : Answer Your code has lots of issues. You were not consistent in your variable names (e.g. pp vs. PurPrice) You only use $ when you want the value of a variable (not on read’s for example). You can’t use strings with the integer test operators (-eq and so on). You need backti…

Bash Array Key from User Input

So I have a bash script which will scan a directory and run a function on a selected input. It seems that for some reason, the key is not setting from the array properly. What am I missing? All help is much appreciated! EDIT: As a side note, I can run the commands separately and get results. Here is the

Unable to write on /dev/* files

I’m writing a basic char device driver for Linux kernel. For this, the code flow I have considered is as follows: alloc_chrdev_region() -> to use dynamic allocation of major number class_create() -> to create device class in sysfs device_creat() -> to create device under /dev/ cdv_init() -> …

Using a glob expression passed as a bash script argument

TL;DR: Why isn’t invoking ./myscript foo* when myscript has var=$1 the same as invoking ./myscript with var=foo* hardcoded? Longer form I’ve come across a weird issue in a bash script I’m writing. I am sure there is a simple explanation, but I can’t figure it out. I am trying to pass a…

shell difference between redirect position

Is there any difference between these 2 lines? Because Robert told me that the first one only makes the I/O OP outside the for loop. But if I type tail -f /tmp/output.txt this is behaving exactly the same way. Answer They do the same if they succeed. However, there might be notable differences if they fail fo…