Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Shell scripting giving weird, stupid results.
New Posts  All Forums:Forum Nav:

Shell scripting giving weird, stupid results.

post #1 of 6
Thread Starter 
I'm trying to write a short script to remove some text from one file.

for example:
Code:
#!/sbin/sh
grep -v "REMOVETHIS" /dir/file.prop > /dir/file.prop.bak
. /dir2/another_shell.sh

another_shell:
Code:
#!/sbin/sh
mv /dir/file.prop.bak /dir/file.prop

This SHOULD create a .bak file... then rename it to the previous name after the string removal has happened.

BUT

The second shell script says

"file.prop.bak not found"

or similar.

So, I run "ls -s" on that directory... the list shows

"file.prop.bak?"

With a ? in the name...

Ok, no problem. Try putting the ? in the mv command... gives me a file.prop? file instead.


Why on earth is it putting the ? in the name?
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
post #2 of 6
The question mark means you have extra character in your script
You probably have a Carriage Return at the end of each line in your script.
Did you write it on a windows box? or maybe copy and past it from somewhere?
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
post #3 of 6
Thread Starter 
Quote:
Originally Posted by tom.slick View Post

The question mark means you have extra character in your script
You probably have a Carriage Return at the end of each line in your script.
Did you write it on a windows box? or maybe copy and past it from somewhere?

I did write it in notepad++ on a Windows machine yeah :/
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
post #4 of 6
Not sure why you're not just using sed
post #5 of 6
Thread Starter 
^ it gives the same result anyway frown.gif I just switched to grep to see if it was any different.
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
post #6 of 6
Quote:
Originally Posted by Rubers View Post

I did write it in notepad++ on a Windows machine yeah :/

Write in vim on the linux box dude.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Shell scripting giving weird, stupid results.